所以我试图使用串口与arduino进行通信。我想要它打印"烧制电机"当我输入1.我在这里有程序:
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);
}
问题在于,而不是返回"烧制电机。"或"请按1开启电机。"所有控制台只返回0.我也尝试删除 - ' 0'
我也试过说:
if (val == 1) {
Serial.print("Firing the motor.");
} else {
Serial.print("Please press 1 to fire the motor.");
}
并添加""而不是'
感谢您的帮助