Only your Arduino Board is needed for this example.
1/*2
3 Simple RTC for Arduino Zero and MKR10004
5 Demonstrates the use of the RTC library for the Arduino Zero and MKR10006
7 This example code is in the public domain8
9 https://www.arduino.cc/en/Tutorial/SimpleRTC10
11 created by Arturo Guadalupi <a.guadalupi@arduino.cc>12
13 15 Jun 201514
15 modified16
17 18 Feb 201618
19 modified by Andrea Richetta <a.richetta@arduino.cc>20
21 24 Aug 201622
23*/24
25#include <RTCZero.h>26
27/* Create an rtc object */28
29RTCZero rtc;30
31/* Change these values to set the current initial time */32
33const byte seconds = 0;34
35const byte minutes = 0;36
37const byte hours = 16;38
39/* Change these values to set the current initial date */40
41const byte day = 15;42
43const byte month = 6;44
45const byte year = 15;46
47void setup()48{49
50 Serial.begin(9600);51
52 rtc.begin(); // initialize RTC53
54 // Set the time55
56 rtc.setHours(hours);57
58 rtc.setMinutes(minutes);59
60 rtc.setSeconds(seconds);61
62 // Set the date63
64 rtc.setDay(day);65
66 rtc.setMonth(month);67
68 rtc.setYear(year);69
70 // you can use also71
72 //rtc.setTime(hours, minutes, seconds);73
74 //rtc.setDate(day, month, year);75}76
77void loop()78{79
80 // Print date...81
82 print2digits(rtc.getDay());83
84 Serial.print("/");85
86 print2digits(rtc.getMonth());87
88 Serial.print("/");89
90 print2digits(rtc.getYear());91
92 Serial.print(" ");93
94 // ...and time95
96 print2digits(rtc.getHours());97
98 Serial.print(":");99
100 print2digits(rtc.getMinutes());101
102 Serial.print(":");103
104 print2digits(rtc.getSeconds());105
106 Serial.println();107
108 delay(1000);109}110
111void print2digits(int number) {112
113 if (number < 10) {114
115 Serial.print("0"); // print a 0 before if the number is < than 10116
117 }118
119 Serial.print(number);120}