How to use "lcd.print( );" for single time item in DS1302 library ? #222
Unanswered
mianqi2016
asked this question in
Q&A
Replies: 2 comments
-
This library doesn't do any string formatting for printing. The examples just include one way of how to do it using Just replace the |
Beta Was this translation helpful? Give feedback.
0 replies
-
Since LiquidCrystal library has no "printf" method, I used a convertor function from Micheal Margolis's library "DS1307RTC":
void print2digits(int number) {
if (number >= 0 && number < 10) {
lcd.print('0');
}
lcd.print(number);
}
and, I changed the code from:
lcd.setCursor(6, 0);
lcd.print(dt.Hour());
lcd.print(':');
lcd.print(dt.Minute());
lcd.print(':');
lcd.print(dt.Second());
into:
lcd.setCursor(6, 0);
print2digits(dt.Hour());
lcd.print(':');
print2digits(dt.Minute());
lcd.print(':');
print2digits(dt.Second());
then, it was OK.
…________________________________
发件人: Michael Miller ***@***.***>
发送时间: 2025年2月27日 0:55
收件人: Makuna/Rtc ***@***.***>
抄送: Mian Qi ***@***.***>; Author ***@***.***>
主题: Re: [Makuna/Rtc] How to use "lcd.print( );" for single time item in DS1302 library ? (Discussion #222)
This library doesn't do any string formatting for printing. The examples just include one way of how to do it using snprintf_P to format a string that then is printed using String.
Just replace the Serial.print(datestring); with lcd.print(datestring); and it should work the same. Then just become familiar with snprintf_P (snprintf, sprintf, printf) and the formatting string.
―
Reply to this email directly, view it on GitHub<#222 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFPCOAUFGCI7FSGUQGQPKL32RZO7HAVCNFSM6AAAAABX6QTKU2VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMZTGI3DGNA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I tested the RTC library for DS1302, the code "Serial.print(datestring);" show time correctly in serial monitor, while "lcd.print(dt.Second());" show seconds in this way:
59-09-19-29-39-49-59-69-79-89-99-10-11-12-...59..., and when there is a minute ypdate, it would show "12:3:009-...999".
My code was:
void printDateTime(const RtcDateTime& dt)
{
char datestring[26];
}
is there any method for this library used on LCD screen?
Beta Was this translation helpful? Give feedback.
All reactions