File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments