-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathExample3_Test_RTC.ino
83 lines (69 loc) · 1.82 KB
/
Example3_Test_RTC.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
Author: Nathan Seidle and stephenf7072
Created: January 28th, 2020
This example test the internal HAL to make sure the days advance correctly.
*/
/*
// This file is subject to the terms and conditions defined in
// file 'LICENSE.md', which is part of this source code package.
*/
#include "RTC.h"
int previousDay;
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println("Artemis RTC Testing");
// Manually set RTC date and time to the start of 2020 so that RTC contains valid times
rtc.setTime(0, 59, 59, 23, 1, 1, 20); // Set to 1 second before midnight Jan 1
}
void loop()
{
rtc.setTime(99, 59, 59, 23, rtc.dayOfMonth, rtc.month, rtc.year); // Manually set RTC 1/100th of a second from the next day
previousDay = rtc.weekday;
delay(11); //Allow us to roll from midnight the night before to the new day
printArtemisTime();
}
void printArtemisTime()
{
char buf[50];
char weekdayBuf[4];
rtc.getTime();
int i = rtc.weekday + 1;
switch (i)
{
case (1):
strcpy(weekdayBuf, "Sun");
break;
case (2):
strcpy(weekdayBuf, "Mon");
break;
case (3):
strcpy(weekdayBuf, "Tue");
break;
case (4):
strcpy(weekdayBuf, "Wed");
break;
case (5):
strcpy(weekdayBuf, "Thu");
break;
case (6):
strcpy(weekdayBuf, "Fri");
break;
case (7):
strcpy(weekdayBuf, "Sat");
break;
default:
strcpy(weekdayBuf, "???");
break;
}
sprintf(buf, "%02d-%02d-%02d (%s) %02d:%02d:%02d.%02d", rtc.year, rtc.month, rtc.dayOfMonth, weekdayBuf, rtc.hour, rtc.minute, rtc.seconds, rtc.hundredths);
Serial.print(buf);
//Move the previous day forward one day and make sure it matches today
if ((previousDay + 1) % 7 != rtc.weekday)
{
Serial.printf(" Error! previousDay: %d today: %d\n", previousDay, rtc.weekday);
while (1){};
}
Serial.println();
}