uint8_t Wheel_getPosition(void)
{
uint8_t position = 0;
Wheel_getValue();
//determine which position the wheel is in
if (positionData > 0x0806)
position = 7 – (positionData – 0x0806) / 260; //scale the data for 8 different positions
else
position = positionData / 260;
{
uint8_t position = 0;
Wheel_getValue();
//determine which position the wheel is in
if (positionData > 0x0806)
position = 7 – (positionData – 0x0806) / 260; //scale the data for 8 different positions
else
position = positionData / 260;
return position;
}
}
下面这句不懂:
if (positionData > 0x0806)
position = 7 – (positionData – 0x0806) / 260; //scale the data for 8 different positions
position = 7 – (positionData – 0x0806) / 260; //scale the data for 8 different positions
为什吗是0X0806
user3854913:
我明白了,这个是经验值,为了齿轮电位器能更接近翻两页,如果是0X7FF,可能误差大了点,不知是不是正确
灰小子:
这段程序是用来判断滚轮位置的。
那个滚轮是一个可调电位器。positionData是一个电压的采样值。
0x0806的选取可能考虑了很多方面,比如容易处理数据、最小电阻等情况,你也可以试着换成其他值的。