-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathExample3_Test_RTC.ino
83 lines (69 loc) · 1.77 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
License: MIT. See SparkFun Arduino Apollo3 Project for more information
This example test the internal HAL to make sure the days advance correctly.
*/
#include "RTC.h"
APM3_RTC myRTC; // Create instance of RTC class
int previousDay = 1;
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println("Artemis RTC Testing");
// Manually set RTC date and time
myRTC.setTime(23, 59, 59, 0, 1, 1, 20); // Set to 1 second before midnight
}
void loop()
{
printArtemisTime();
myRTC.getTime();
myRTC.setTime(23, 59, 59, 99, myRTC.dayOfMonth, myRTC.month, myRTC.year); // Manually set RTC
delay(11); //Allow us to roll from midnight the night before to the new day
}
void printArtemisTime()
{
char buf[50];
char weekdayBuf[4];
myRTC.getTime();
int i = myRTC.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", myRTC.year, myRTC.month, myRTC.dayOfMonth, weekdayBuf, myRTC.hour, myRTC.minute, myRTC.seconds, myRTC.hundredths);
Serial.print(buf);
//Move the previous day forward one day and make sure it matches today
if ((previousDay + 1) % 7 != myRTC.weekday)
{
Serial.printf(" Error! previousDay: %d today: %d\n", previousDay, myRTC.weekday);
while (1)
;
}
previousDay = myRTC.weekday;
Serial.println();
}