11/*
22 Simple RTC for Arduino Zero and MKR1000
33
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
55
6- This example code is in the public domain
6+ This example code is in the public domain
77
8- http://arduino.cc/en/Tutorial/SimpleRTC
8+ http://arduino.cc/en/Tutorial/SimpleRTC
99
1010 created by Arturo Guadalupi <a.guadalupi@arduino.cc>
1111 15 Jun 2015
12-
13- modified
12+ modified
1413 18 Feb 2016
14+ modified by Andrea Richetta <a.richetta@arduino.cc>
15+ 24 Aug 2016
1516*/
1617
1718#include < RTCZero.h>
@@ -32,19 +33,19 @@ const byte year = 15;
3233void setup ()
3334{
3435 Serial.begin (9600 );
35-
36+
3637 rtc.begin (); // initialize RTC
37-
38+
3839 // Set the time
3940 rtc.setHours (hours);
4041 rtc.setMinutes (minutes);
4142 rtc.setSeconds (seconds);
42-
43+
4344 // Set the date
4445 rtc.setDay (day);
4546 rtc.setMonth (month);
4647 rtc.setYear (year);
47-
48+
4849 // you can use also
4950 // rtc.setTime(hours, minutes, seconds);
5051 // rtc.setDate(day, month, year);
@@ -53,21 +54,30 @@ void setup()
5354void loop ()
5455{
5556 // Print date...
56- Serial. print (rtc.getDay ());
57+ print2digits (rtc.getDay ());
5758 Serial.print (" /" );
58- Serial. print (rtc.getMonth ());
59+ print2digits (rtc.getMonth ());
5960 Serial.print (" /" );
60- Serial. print (rtc.getYear ());
61- Serial.print (" \t " );
62-
61+ print2digits (rtc.getYear ());
62+ Serial.print (" " );
63+
6364 // ...and time
64- Serial. print (rtc.getHours ());
65+ print2digits (rtc.getHours ());
6566 Serial.print (" :" );
66- Serial. print (rtc.getMinutes ());
67+ print2digits (rtc.getMinutes ());
6768 Serial.print (" :" );
68- Serial. print (rtc.getSeconds ());
69-
69+ print2digits (rtc.getSeconds ());
70+
7071 Serial.println ();
71-
72+
7273 delay (1000 );
7374}
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