C中是否有類似於Arduino的地圖?我已經搜索,但我找不到任何類似的東西,我可以使用。 現在我得到了從50到700的值,但我想映射它們使得50是0而700是1023.有沒有辦法在C中做到這一點?c中的地圖值
void backRight(void)
{
printf("Ch5 %i\n", readADC(ADC_CHANNEL_5));
error5 = setpoint5 - (float)readADC(ADC_CHANNEL_5);
printf("error 5 %i\n", (int) error5);
if(abs(error5) > MIN5)
{
integral5 = integral5 + error5 * dt5;
}
derivative5 = (error5 - pre_error5)/dt5;
output5 = Kp5 * error5 + Ki5 * integral5 + Kd5 * derivative5;
printf("Output %i\n",(int) output5);
if(output5 > MAX5)
{
output5 = MAX5;
}
else if(output5 < MIN5)
{
output5 = MIN5;
}
pre_error5 = error5;
printf("output5 %i\n", (int)output5);
changeDutyCycle(pwm_pin8, (output5/1023)*100);
}
這與詞典無關(請參閱我的答案)。 – Olaf
@pid:爲什麼拒絕?這個問題顯然是關於線性轉換函數,而不是數據結構「字典」。 – Olaf
而且'map'函數通常也會從函數式編程中觸發與'map()'函數的關聯。 – Olaf