Skip to content

Commit 44faa41

Browse files
author
JChristensen
committed
Fix bugs in SetSerial and rtcSet2 example sketches that cause day of week (tmElements_t.Wday) to be set incorrectly.
1 parent 2807f32 commit 44faa41

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

examples/SetSerial/SetSerial.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void loop(void)
102102
tm.Minute = Serial.parseInt();
103103
tm.Second = Serial.parseInt();
104104
t = makeTime(tm);
105-
RTC.write(tm);
105+
RTC.set(t); //use the time_t value to ensure correct weekday is set
106106
setTime(t);
107107
Serial << F("RTC set to: ");
108108
printDateTime(t);

examples/rtcSet2/rtcSet2.pde

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ void setup(void)
2929
delay(2000);
3030
Serial.begin(9600);
3131

32-
tm.Hour = 23; //set the tm structure to 23h31m30s on 13Feb2009
32+
tm.Hour = 23; //set the tm structure to 23h31m30s on Fri 13Feb2009
3333
tm.Minute = 31;
3434
tm.Second = 30;
3535
tm.Year = 2009 - 1970; //tmElements_t.Year is the offset from 1970.
3636
tm.Month = 2;
3737
tm.Day = 13;
38+
tm.Wday = dowFriday; //See enum in Time.h: Sun=1, Mon=2, ... Sat=7
3839
RTC.write(tm); //set the RTC from the tm structure
3940
}
4041

examples/rtcSetSerial/rtcSetSerial.pde

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ void readCommand()
7272
tmSet.Hour = 10 * (cmd[15] - '0') + cmd[16] - '0';
7373
tmSet.Minute = 10 * (cmd[18] - '0') + cmd[19] - '0';
7474
tmSet.Second = 10 * (cmd[21] - '0') + cmd[22] - '0';
75-
tSet = makeTime(tmSet); //convert to time_t
76-
setTime(tSet); //set the system time
77-
RTC.set(now()); //set the rtc
75+
tSet = makeTime(tmSet); //convert to time_t
76+
setTime(tSet); //set the system time
77+
RTC.set(now()); //set the rtc
7878
Serial.println("RTC set!");
7979
flushInput(); //discard any extraneous trailing characters
8080
}

0 commit comments

Comments
 (0)