1
1
/*
2
2
Simple RTC for Arduino Zero and MKR1000
3
3
4
- Demonstrates the use of the RTC library for the Arduino Zero and MKR1000
4
+ Demonstrates the use of the RTC library for the Arduino Zero and MKR1000
5
5
6
- This example code is in the public domain
6
+ This example code is in the public domain
7
7
8
- http://arduino.cc/en/Tutorial/SimpleRTC
8
+ http://arduino.cc/en/Tutorial/SimpleRTC
9
9
10
10
created by Arturo Guadalupi <[email protected] >
11
11
15 Jun 2015
12
-
13
- modified
12
+ modified
14
13
18 Feb 2016
14
+ modified by Andrea Richetta <[email protected] >
15
+ 24 Aug 2016
15
16
*/
16
17
17
18
#include < RTCZero.h>
@@ -32,19 +33,19 @@ const byte year = 15;
32
33
void setup ()
33
34
{
34
35
Serial.begin (9600 );
35
-
36
+
36
37
rtc.begin (); // initialize RTC
37
-
38
+
38
39
// Set the time
39
40
rtc.setHours (hours);
40
41
rtc.setMinutes (minutes);
41
42
rtc.setSeconds (seconds);
42
-
43
+
43
44
// Set the date
44
45
rtc.setDay (day);
45
46
rtc.setMonth (month);
46
47
rtc.setYear (year);
47
-
48
+
48
49
// you can use also
49
50
// rtc.setTime(hours, minutes, seconds);
50
51
// rtc.setDate(day, month, year);
@@ -53,21 +54,30 @@ void setup()
53
54
void loop ()
54
55
{
55
56
// Print date...
56
- Serial. print (rtc.getDay ());
57
+ print2digits (rtc.getDay ());
57
58
Serial.print (" /" );
58
- Serial. print (rtc.getMonth ());
59
+ print2digits (rtc.getMonth ());
59
60
Serial.print (" /" );
60
- Serial. print (rtc.getYear ());
61
- Serial.print (" \t " );
62
-
61
+ print2digits (rtc.getYear ());
62
+ Serial.print (" " );
63
+
63
64
// ...and time
64
- Serial. print (rtc.getHours ());
65
+ print2digits (rtc.getHours ());
65
66
Serial.print (" :" );
66
- Serial. print (rtc.getMinutes ());
67
+ print2digits (rtc.getMinutes ());
67
68
Serial.print (" :" );
68
- Serial. print (rtc.getSeconds ());
69
-
69
+ print2digits (rtc.getSeconds ());
70
+
70
71
Serial.println ();
71
-
72
+
72
73
delay (1000 );
73
74
}
75
+
76
+
77
+
78
+ void print2digits (int number) {
79
+ if (number < 10 ) {
80
+ Serial.print (" 0" ); // print a 0 before if the number is < than 10
81
+ }
82
+ Serial.print (number);
83
+ }
0 commit comments