【发布时间】:2011-04-13 12:49:46
【问题描述】:
好的,下一个问题是:如果我在数字输入端添加了一个按钮,我可以使用它来将电位器校准为零吗?
当我按下按钮时,无论罐子在什么位置,所有值都从零开始?之后我打算在 Excel 中执行此操作,但是今天下午似乎可以尝试。你会使用 switch 语句还是某种 if 语句?
float ZPot = 0;
float YPot = 1;
float XPot = 2;
byte Reset = 10;
void setup()
{
pinMode(XPot, INPUT);
pinMode(YPot, INPUT);
pinMode(ZPot, INPUT);
pinMode(Reset, INPUT);
Serial.begin(9600);
}
void loop()
{
ZPot = analogRead(0)/ 1023.0 * 105.0;
YPot = analogRead(1)/ 1023.0 * 105.0;
XPot = analogRead(2)/ 1023.0 * 105.0;
Reset = digitalRead(10);
Serial.print("X Pot [mm] = ");
Serial.print(XPot );
delay(500);
Serial.print(" Y Pot [mm] = ");
Serial.print(YPot );
delay(500);
Serial.print(" Z Pot [mm] = ");
Serial.println (ZPot );
delay(500);
}
【问题讨论】:
-
请创建另一个问题不要编辑旧问题,我们最终会得到大多数毫无意义的评论......
-
Alex,我已经更新了我的解决方案以包括校准。请注意,我已将 Reset 更改为 int,而不是 byte。
标签: arduino zero calibration