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