Hello dear friends...
I´m making a clock with RTC DS1307 module and RTClib.
The libary give me the hour format like 16:2, and i want to write like 16:02 on LCD.
The libary example use the code: Serial.print(now.minute(), DEC);
Does anyone can help me?
Thank you!
8)
Patrick
Just check to see if the 0 is required then print one if it is.
if (now.minute() <=9)
{ Serial.print("0"); }
Serial.print(now.minute(),DEC);
It is very simple: if(minute < 10)...
or
you can use functions like sprintf for formatted output.
@adwsystems
I suggest to take now.minute() into the variable for second use.
Budvar10:
@adwsystems
I suggest to take now.minute() into the variable for second use.
I know that. Since the original program was no supplied and the code snippet (one line) rudimentary, I was not going to complicate things. Yes, setting it to a variable is a better way in the event that you happen to execute the if statement the microsecond before the minute changes from 9 to 10 or from 59 to 0.
Typically I call a subroutine that returns a formatted char array with the desired delimiters and number formatting all done.
Thank you guys for all answers!
I follow that tips to use "minute < 10" as you can see:
if (now.hour() < 10) { ...
}
Is all right now!
thank you soo much again!
-