【问题标题】:Arduino Micro Serial.print string not returning a stringArduino Micro Serial.print 字符串不返回字符串
【发布时间】: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


    【解决方案1】:

    您是否将显示器设置为相同的波特率? (9600) 我的意思是这里 image

    【讨论】:

    • 是的,设置为9600
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多