Skip to content

Commit 9b18daa

Browse files
committed
Create Example3_Test_RTC.ino
1 parent d16b64b commit 9b18daa

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Author: Nathan Seidle and stephenf7072
3+
Created: January 28th, 2020
4+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
5+
6+
This example test the internal HAL to make sure the days advance correctly.
7+
*/
8+
9+
#include "RTC.h"
10+
APM3_RTC myRTC; // Create instance of RTC class
11+
12+
int previousDay = 1;
13+
14+
void setup()
15+
{
16+
Serial.begin(115200);
17+
delay(10);
18+
Serial.println("Artemis RTC testing");
19+
20+
//myRTC.setTime(hund, ss, mm, hh, dd, mm, yy);
21+
myRTC.setTime(0, 59, 59, 23, 1, 1, 20); // Manually set RTC to 1s before midnight
22+
}
23+
24+
void loop()
25+
{
26+
printArtemisTime();
27+
28+
myRTC.getTime();
29+
myRTC.setTime(99, 59, 59, 23, myRTC.dayOfMonth, myRTC.month, myRTC.year); //Manually set RTC
30+
delay(11); //Allow us to roll from midnight the night before to the new day
31+
}
32+
33+
void printArtemisTime()
34+
{
35+
char buf[50];
36+
char weekdayBuf[4];
37+
38+
myRTC.getTime();
39+
int i = myRTC.weekday + 1;
40+
switch (i)
41+
{
42+
case (1):
43+
strcpy(weekdayBuf, "Sun");
44+
break;
45+
case (2):
46+
strcpy(weekdayBuf, "Mon");
47+
break;
48+
case (3):
49+
strcpy(weekdayBuf, "Tue");
50+
break;
51+
case (4):
52+
strcpy(weekdayBuf, "Wed");
53+
break;
54+
case (5):
55+
strcpy(weekdayBuf, "Thu");
56+
break;
57+
case (6):
58+
strcpy(weekdayBuf, "Fri");
59+
break;
60+
case (7):
61+
strcpy(weekdayBuf, "Sat");
62+
break;
63+
64+
default:
65+
strcpy(weekdayBuf, "???");
66+
break;
67+
}
68+
69+
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);
70+
Serial.print(buf);
71+
72+
//Move the previous day forward one day and make sure it matches today
73+
if ((previousDay + 1) % 7 != myRTC.weekday)
74+
{
75+
Serial.printf(" Error! previousDay: %d today: %d\n", previousDay, myRTC.weekday);
76+
while (1)
77+
;
78+
}
79+
80+
previousDay = myRTC.weekday;
81+
82+
Serial.println();
83+
}

0 commit comments

Comments
 (0)