简体   繁体   English

LCD Arduino 显示不正确

[英]LCD Arduino not displaying correctly

My problem is when I input the string in the serial monitor it shows like this:我的问题是当我在串行监视器中输入字符串时,它显示如下:

LCD Arduino Error The setCursor dont work and also there is another weird character created before the actual output. LCD Arduino 错误setCursor 不起作用,并且在实际 output 之前创建了另一个奇怪的字符。

This is my sample code:这是我的示例代码:

void setup() {

    lcd.begin(16, 2);
    Serial.begin(9600);
    lcd.print("hello, world!");
}

void loop() {

    String readString;
    String Q;
    while (Serial.available()) {
        delay(1);
        if (Serial.available()>0) {
            char c = Serial.read();
            if(isControl(c)){
                break;
            }
            readString += c;
        }
    }
    Q = readString;
    if (Q == "1"){
        lcd.setCursor(0,1);
        lcd.print("Hello");
    }
    if (Q == "2"){
        lcd.setCursor(0,1);
        lcd.print("World");
    }
}

First of all you should understand the LCD lib functions.首先,您应该了解 LCD 库函数。
To set the cursorto theFirst row you need要将光标设置到您需要的第一行

 lcd.setCursor(0,0);  // row index starts with 0

if you only set the cursor back without clearing the screen there might be weird chars,sodo a如果您只设置 cursor 而不清除屏幕,可能会有奇怪的字符,sodo a

 lcd.clear(); //clears the whole screen

OR define an empty String:或者定义一个空字符串:

 String lineClear ="                ";  // should be 16 spaces for a 16x2 display

and do as a clearing sequence (eg for the top line)并作为清算序列(例如,用于顶线)

 lcd.setCursor(0,0);
 lcd.print(lineClear);
 lcd.print("Hello");

Remember the syntax is记住语法是

 lcd.setCursor(col, row)  
 // index for 16x2 is col 0-15,row 0-1 
 // index for 20x4 is col 0-19,row 0-3 

and in setup alwas do a并且在设置中总是做一个

lcd.clear(); 

after initializing the lcd, to remove possible artefacts from the buffer初始化液晶显示器后,从缓冲区中删除可能的伪影

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM