It works as expected for a few seconds and then random letters appear on the second row. The wiring and the programming should be correct. I wired it according to an Arduino Starter Kit Book and coded it myself.
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int hours=23;
int minutes=0;
String none="00";
unsigned long timer;
void setup() {
lcd.begin(16, 2);
lcd.setCursor(6, 0);
lcd.print("Time:");
lcd.setCursor(6, 1);
lcd.print("23:00");
}
void loop() {
timer=millis();
if(timer%600==0){
minutes++;
if(minutes==60){
minutes=0;
hours++;
}
if(hours==24){
hours=0;
}
lcd.clear();
lcd.setCursor(6, 0);
lcd.print("Time:");
lcd.setCursor(6, 1);
if(minutes<10){
if(hours<10){
lcd.print(String("0")+hours+":"+"0"+minutes);
}
else{
lcd.print(hours+String(":")+"0"+minutes);
}
}
else{
if(hours<10){
lcd.print(String("0")+hours+":"+minutes);
}
else{
lcd.print(hours+":"+minutes);
}
}
delay(200);
}
}
I was able to narrow down the problem. I was testing what happens when it hits 24 hours so I set hours to 23 in the beginning and made the time 600 ms. Once it hits 10 seconds, the characters appear. If the hour is a 2 digit number, the issue happens. I made the hours 9, and the issue disappeared. What can I do?