[136] | 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 12 hour mode
|
---|
| 4 | **********************************************************************************************************************************************************/
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | #include <RTCInt.h>
|
---|
| 9 |
|
---|
| 10 | RTCInt rtc; //create an RTCInt type object
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | void setup()
|
---|
| 14 | {
|
---|
| 15 | Serial.begin(9600);
|
---|
| 16 | rtc.begin(TIME_H12); //init RTC in 12 hour mode
|
---|
| 17 |
|
---|
| 18 | //filling internal structure for time
|
---|
| 19 | rtc.local_time.hour = 10; //hour
|
---|
| 20 | rtc.local_time.minute = 44; //minute
|
---|
| 21 | rtc.local_time.second = 0; //second
|
---|
| 22 | rtc.local_time.Tmode = ANTI_MERIDIAN;
|
---|
| 23 |
|
---|
| 24 | //filling internal structure for date
|
---|
| 25 | rtc.local_date.day = 13; //day
|
---|
| 26 | rtc.local_date.month = 8; //month
|
---|
| 27 | rtc.local_date.year = 15; //year
|
---|
| 28 |
|
---|
| 29 | rtc.setTime(); //setting time
|
---|
| 30 | rtc.setDate(); //setting date
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | void loop()
|
---|
| 39 | {
|
---|
| 40 | rtc.getDate(); //getting date in local structure (local_date)
|
---|
| 41 | rtc.getTime(); //getting time in local structure(local_time)
|
---|
| 42 |
|
---|
| 43 | //printing date in format YYYY/MM/DD
|
---|
| 44 | Serial.print(rtc.local_date.year+2000); // year
|
---|
| 45 | Serial.print('/');
|
---|
| 46 | Serial.print(rtc.local_date.month); // month
|
---|
| 47 | Serial.print('/');
|
---|
| 48 | Serial.print(rtc.local_date.day); // day
|
---|
| 49 | Serial.print(' ');
|
---|
| 50 |
|
---|
| 51 | //printing time
|
---|
| 52 | Serial.print(rtc.local_time.hour); //hour
|
---|
| 53 | Serial.print(':');
|
---|
| 54 | Serial.print(rtc.local_time.minute); //minute
|
---|
| 55 | Serial.print(':');
|
---|
| 56 | Serial.print(rtc.local_time.second); //second
|
---|
| 57 | Serial.print (' ');
|
---|
| 58 | if(rtc.local_time.Tmode == ANTI_MERIDIAN) Serial.println("AM"); // print AM or PM
|
---|
| 59 | else Serial.println("PM");
|
---|
| 60 |
|
---|
| 61 | delay(1000);
|
---|
| 62 | }
|
---|