I have time late in my Tiny RTC when i try to set time at sketch downloading. Library: RTClib.h
Setup line:
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
The problem is that my computer displays 15:45 and Serial.print displays 15:12. How can i fix that ?
__TIME__is the time the sketch was compiled, not when the board starts running. It was compiled at 15:12, but you applied power at 15:45...? – Majenko Feb 16 '22 at 23:40Serial.println(F(__TIME__)). This will show you the time that you attempted to set in the RTC, which is your compiler's idea of the current time when it is doing the compilation. – Edgar Bonet Feb 17 '22 at 09:49if (rtc.lostPower()) {-- That is, if the RTC loses power then reset the time to what it was back when you compiled the sketch. If you want to set the time to now then you will need to include some mechanism to either query the time from somewhere or allow the user to set the time manually. – Majenko Feb 17 '22 at 10:17