Skip to content

Commit 2cf56bf

Browse files
committed
Create Example4_Set_Epoch.ino
1 parent d833ca1 commit 2cf56bf

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
}

0 commit comments

Comments
 (0)