【发布时间】:2016-06-17 11:47:50
【问题描述】:
所以我正在尝试使用串行与 arduino 进行通信。我希望它在我输入 1 时打印“Firing the motor”。我在这里有程序:
void setup() {
Serial.begin(9600); //Connect to the serial monitor console
}
void loop() {
while (Serial.available() == 0); //Wait until Serial is available
//Read val
int val = Serial.read() - '0'; //Val that represents input
Serial.print(val);
delay(1000);
if (val == 1) {
Serial.print('Firing the motor.');
} else {
Serial.print('Please press 1 to fire the motor.');
}
delay(4000);
}
问题在于,它没有返回“Firing the motor”。或“请按 1 启动电机。”所有控制台都只返回 0。我也尝试删除 - '0'
我也试过说:
if (val == 1) {
Serial.print("Firing the motor.");
} else {
Serial.print("Please press 1 to fire the motor.");
}
并添加“”而不是''
感谢您的帮助
【问题讨论】:
标签: arduino