Skip to content

Commit 951458b

Browse files
committed
Add example for Epoch API's
1 parent 5975b88 commit 951458b

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

examples/Epoch/Epoch.ino

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Epoch time example for Arduino Zero
3+
4+
Demonstrates the use of the RTC library for the Arduino Zero
5+
6+
This example code is in the public domain
7+
8+
created by Sandeep Mistry <[email protected]>
9+
31 Dec 2015
10+
*/
11+
12+
#include <RTCZero.h>
13+
14+
/* Create an rtc object */
15+
RTCZero rtc;
16+
17+
void setup() {
18+
Serial.begin(9600);
19+
20+
rtc.begin(); // initialize RTC
21+
22+
rtc.setEpoch(1451606400); // Jan 1, 2016
23+
}
24+
25+
void loop() {
26+
Serial.print("Unix time = ");
27+
Serial.println(rtc.getEpoch());
28+
29+
Serial.print("Seconds since Jan 1 2000 = ");
30+
Serial.println(rtc.getY2kEpoch());
31+
32+
// Print date...
33+
Serial.print(rtc.getDay());
34+
Serial.print("/");
35+
Serial.print(rtc.getMonth());
36+
Serial.print("/");
37+
Serial.print(rtc.getYear());
38+
Serial.print("\t");
39+
40+
// ...and time
41+
print2digits(rtc.getHours());
42+
Serial.print(":");
43+
print2digits(rtc.getMinutes());
44+
Serial.print(":");
45+
print2digits(rtc.getSeconds());
46+
47+
Serial.println();
48+
49+
delay(1000);
50+
}
51+
52+
void print2digits(int number) {
53+
if (number < 10) {
54+
Serial.print("0");
55+
}
56+
Serial.print(number);
57+
}
58+

0 commit comments

Comments
 (0)