1 | /**********************************************************************************************************************************************************
|
---|
2 | This sketch gives a simple demonstration of how to use RTC library.
|
---|
3 | The code sets date and time using internal structure and then print on serial date and time. Time representation is 24 hour mode
|
---|
4 |
|
---|
5 | NOTE: for M0/M0 pro only you can select the oscillator source for count.
|
---|
6 | If you want to use a low power oscillator use rtc.begin(TIME_H24, LOW_POWER); function.
|
---|
7 | If you want to use a more accurate oscillator use rtc.begin(TIME_H24, HIGH_PRECISION); function.
|
---|
8 | **********************************************************************************************************************************************************/
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 | #include <RTCInt.h>
|
---|
13 |
|
---|
14 | RTCInt rtc; //create an RTCInt type object
|
---|
15 |
|
---|
16 |
|
---|
17 | void setup()
|
---|
18 | {
|
---|
19 | Serial.begin(9600);
|
---|
20 | rtc.begin(TIME_H24); //init RTC in 12 hour mode
|
---|
21 |
|
---|
22 | //time settings
|
---|
23 | rtc.setHour(15,0); //setting hour
|
---|
24 | rtc.setMinute(43); //setting minute
|
---|
25 | rtc.setSecond(0); //setting second
|
---|
26 |
|
---|
27 |
|
---|
28 | rtc.setDay(13); //setting day
|
---|
29 | rtc.setMonth(8); //setting month
|
---|
30 | rtc.setYear(15); //setting year
|
---|
31 |
|
---|
32 | }
|
---|
33 |
|
---|
34 | void loop()
|
---|
35 | {
|
---|
36 | rtc.getDate(); //getting date in local structure (local_date)
|
---|
37 | rtc.getTime(); //getting time in local structure(local_time)
|
---|
38 |
|
---|
39 | //printing date in format YYYY/MM/DD
|
---|
40 | Serial.print(rtc.date.year+2000); // year
|
---|
41 | Serial.print('/');
|
---|
42 | Serial.print(rtc.date.month); // month
|
---|
43 | Serial.print('/');
|
---|
44 | Serial.print(rtc.date.day); // day
|
---|
45 | Serial.print(' ');
|
---|
46 |
|
---|
47 | //printing time
|
---|
48 | Serial.print(rtc.time.hour); //hour
|
---|
49 | Serial.print(':');
|
---|
50 | Serial.print(rtc.time.minute); //minute
|
---|
51 | Serial.print(':');
|
---|
52 | Serial.println(rtc.time.second); //second
|
---|
53 |
|
---|
54 | delay(1000);
|
---|
55 | }
|
---|