File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
libraries/RTC/examples/Example4_Set_Epoch Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Author: Adam Garbo
3+ Created: May 23rd, 2020
4+ License: MIT. See SparkFun Arduino Apollo3 Project for more information
5+
6+ This example demonstrates how to set the RTC using UNIX Epoch time.
7+
8+ Most SparkFun Artemis boards have the necessary external 32kHz crystal to
9+ enable the RTC. If you are using the Artemis module bare you will either
10+ need an external 32kHz xtal or use the internal LFRC. Read the datasheet
11+ section 12.1 for more information.
12+
13+ */
14+
15+ #include " RTC.h" // Include RTC library included with the Aruino_Apollo3 core
16+ APM3_RTC myRTC; // Create instance of RTC class
17+
18+ void setup ()
19+ {
20+ Serial.begin (115200 );
21+ Serial.println (" SparkFun RTC Set UNIX Epoch Time Example" );
22+
23+ // Set the RTC time using UNIX Epoch time
24+ myRTC.setEpoch (1590240780 ); // E.g. Saturday, May 23, 2020 1:33:00 PM
25+ }
26+
27+ void loop ()
28+ {
29+ Serial.print (" Epoch time: " ); Serial.println (myRTC.getEpoch ());
30+ Serial.print (" Timestamp: " ); printDateTime ();
31+
32+ delay (1000 );
33+ }
34+
35+ // Print the RTC's current date and time
36+ void printDateTime ()
37+ {
38+ myRTC.getTime ();
39+ char dateTime[20 ];
40+ sprintf (dateTime, " 20%02d-%02d-%02d %02d:%02d:%02d" ,
41+ myRTC.year , myRTC.month , myRTC.dayOfMonth ,
42+ myRTC.hour , myRTC.minute , myRTC.seconds );
43+ Serial.println (dateTime);
44+ }
You can’t perform that action at this time.
0 commit comments