@@ -37,36 +37,52 @@ On the header that is located by the barrel jack, you'll find the VRTC pin. And
3737
3838![ Battery Pack Powering the UNO R4 WiFi RTC] ( ./assets/Circuit.png )
3939
40- The following sketch will start the RTC but only set the time if it is not already running .
40+ The following sketch will start the RTC but only set the time if it this is the first time starting the board since adding the VRTC battery .
4141
4242``` arduino
4343#include "RTC.h"
4444
4545void setup() {
46- // put your setup code here, to run once:
4746 Serial.begin(9600);
4847 RTC.begin();
49- RTCTime mytime(24, Month::MAY, 2023, 11, 8, 0, DayOfWeek::THURSDAY, SaveLight::SAVING_TIME_ACTIVE);
5048
51- RTC.setTimeIfNotRunning(mytime);
52-
49+ RTCTime mytime(6, Month::NOVEMBER, 2023, 18, 12, 00, DayOfWeek::MONDAY, SaveLight::SAVING_TIME_ACTIVE);
50+
51+ RTCTime savedTime;
52+ RTC.getTime(savedTime);
53+
54+ if (!RTC.isRunning()) {
55+ // this means the RTC is waking up "as new"
56+ if (savedTime.getYear() == 2000) {
57+ RTC.setTime(mytime);
58+ } else {
59+ RTC.setTime(savedTime);
60+ }
61+ }
5362}
5463
5564void loop() {
56- // put your main code here, to run repeatedly:
57-
65+
5866 RTCTime currenttime;
5967 RTC.getTime(currenttime);
60-
61- int hours = currenttime.getHour();
62- int minutes = currenttime.getMinutes();
63-
64-
65- Serial.print("Hours: ");
66- Serial.println(hours);
67- Serial.println("Minutes: ");
68- Serial.println(minutes);
69-
68+ Serial.print("Current time: ");
69+
70+ /* DATE */
71+ Serial.print(currenttime.getDayOfMonth());
72+ Serial.print("/");
73+ Serial.print(Month2int(currenttime.getMonth()));
74+ Serial.print("/");
75+ Serial.print(currenttime.getYear());
76+ Serial.print(" - ");
77+
78+ /* HOURS:MINUTES:SECONDS */
79+ Serial.print(currenttime.getHour());
80+ Serial.print(":");
81+ Serial.print(currenttime.getMinutes());
82+ Serial.print(":");
83+ Serial.println(currenttime.getSeconds());
84+
85+ delay(1000);
7086}
7187
7288```
0 commit comments