Arduino 无法在 loop() 函数中写入 lcd 屏幕

Arduino cannot write to lcd screen in loop() function

我正在尝试在接收串行数据时在 lcd 屏幕上打印内容。它是这样工作的:

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  lcd.write("hello");
}

void loop() {
    if (Serial.available() == 5) {
        inputByte_0 = Serial.read();
        delay(10);    
        inputByte_1 = Serial.read();
        delay(10);      
        inputByte_2 = Serial.read();
        delay(10);      
        inputByte_3 = Serial.read();
        delay(10);
        inputByte_4 = Serial.read(); 
    }
    if (inputByte_0 == 9) {
        Serial.println("hi");
        lcd.write("whats up?");
    }
}

它在启动时写入"hello"。当我发送正确的字节时,它会向我发送 "hi" 消息,但它不会在屏幕上写入任何内容。我究竟做错了什么?谢谢!

我会尝试使用 lcd.print("String") 而不是 lcd.write 看看是否可行

不要使用 lcd.write() 函数在 LCD 上打印字符串。而是使用函数 lcd.print("Your String").

lcd.write 和 lcd.print 属于相同的 class LiquidCrystal 但唯一的区别是打印函数会将参数转换为字符串但是 write() 函数不会。

考虑使用 lcd.print();