deeveeABC
deeveeABC

Reputation: 986

LCD and RTC_DS1307- Unable to print the 1-9 digit seconds on the lcd correctly

I am connected my RTC module and LCD to my Arduino. The time print correctly, however when it is e.g. 10:13:09 in real time, on the lcd it gets printed out as 10:13:19. When it gets to 10:13:10 it prints out fine. Example: 10:13:58

10:13:59

10:14:10

10:14:11 ... Here is the problem

10:14:19 Here is the problem

10:14:10

10:14:11... etc

My code for this (not sure where I am going wrong):

 //time displayed on lcd
lcd.setCursor(4, 0);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
if(Serial.print(now.second(), DEC) >= 10){
   lcd.setCursor(10,0);
   lcd.print(now.second(), DEC);
}
else if(Serial.print(now.second(), DEC) < 10){
  lcd.setCursor(11,0);
  lcd.print(now.second(), DEC);
  lcd.setCursor(10,0);
  lcd.print(" ");
} 

Could someone help me with this code please?

Upvotes: 0

Views: 233

Answers (1)

Rama
Rama

Reputation: 3305

The code shoud by:

 //time displayed on lcd
lcd.setCursor(4, 0);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
if(now.second() >= 10){
   lcd.setCursor(10,0);
   lcd.print(now.second(), DEC);
}
else if(now.second() < 10){
  lcd.setCursor(11,0);
  lcd.print(now.second(), DEC);
  lcd.setCursor(10,0);
  lcd.print(" ");
} 

Remove Serial.print inside the if Serial.print(now.second(), DEC) returns the number of bytes sended to the serial port. https://www.arduino.cc/en/Serial/Print It is not usefull here.

Upvotes: 2

Related Questions