简体   繁体   中英

Lcd screen prints weird symbols instead of numbers

I am trying to make a alarm clock with the raspberry pi and an arduino. I have been having this problem that when i use serial communication to send a number it, the lcd doesnt print the number. I know that the arduino is getting the number, for some reason it just wont print it. It instead prints weird symbols and lines. This article shows how i use serial communication between them This is my arduino code.

#include <LiquidCrystal.h>


const int ledPin = 13;
LiquidCrystal lcd(12,11,5,4,3,2);
void setup()
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.setCursor(0,1);
  lcd.print("crystralball");
}

void loop()
{

  if (Serial.available())
  {
     flash(Serial.read() - '0');
  }
  delay(1000);
}

void flash(int n)
{
  for (int i = 0; i < n; i++)
  {
    digitalWrite(ledPin, HIGH);
    lcd.clear();
    lcd.write(n);
    Serial.print(n);
    Serial.flush();
    delay(100);
    digitalWrite(ledPin, LOW);
    delay(100);
  }

}

Hi try to change your code in loop like this.

for (int i = 0; i < n; i++){
    digitalWrite(ledPin, HIGH);
    lcd.clear();
    lcd.print(String(n));
    Serial.print(n);
    Serial.flush();
    delay(100);
    digitalWrite(ledPin, LOW);
    delay(100);
}

You have to use the method print and passing a string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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