source: rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/libraries/RTC/examples/RTC_simple/RTC_simple.ino@ 259

Last change on this file since 259 was 259, checked in by ertl-honda, 8 years ago

1.7.11に対応.

File size: 2.0 KB
Line 
1/**********************************************************************************************************************************************************
2This sketch gives a simple demonstration of how to use RTC library.
3The code sets date and time using internal structure and then print on serial date and time. Time representation is 12 hour mode
4
5NOTE: for M0/M0 pro only you can select the oscillator source for count.
6If you want to use a low power oscillator use rtc.begin(TIME_H12, LOW_POWER); function.
7If you want to use a more accurate oscillator use rtc.begin(TIME_H12, HIGH_PRECISION); function.
8**********************************************************************************************************************************************************/
9
10
11
12#include <RTCInt.h>
13
14RTCInt rtc; //create an RTCInt type object
15
16
17void setup()
18{
19 Serial.begin(9600);
20 rtc.begin(TIME_H12); //init RTC in 12 hour mode
21
22 //filling internal structure for time
23 rtc.time.hour = 10; //hour
24 rtc.time.minute = 44; //minute
25 rtc.time.second = 0; //second
26 rtc.time.Tmode = ANTI_MERIDIAN;
27
28 //filling internal structure for date
29 rtc.date.day = 13; //day
30 rtc.date.month = 8; //month
31 rtc.date.year = 15; //year
32
33 rtc.setTime(); //setting time
34 rtc.setDate(); //setting date
35
36
37
38
39
40}
41
42void loop()
43{
44 rtc.getDate(); //getting date in local structure (local_date)
45 rtc.getTime(); //getting time in local structure(local_time)
46
47 //printing date in format YYYY/MM/DD
48 Serial.print(rtc.date.year+2000); // year
49 Serial.print('/');
50 Serial.print(rtc.date.month); // month
51 Serial.print('/');
52 Serial.print(rtc.date.day); // day
53 Serial.print(' ');
54
55 //printing time
56 Serial.print(rtc.time.hour); //hour
57 Serial.print(':');
58 Serial.print(rtc.time.minute); //minute
59 Serial.print(':');
60 Serial.print(rtc.time.second); //second
61 Serial.print (' ');
62 if(rtc.time.Tmode == ANTI_MERIDIAN) Serial.println("AM"); // print AM or PM
63 else Serial.println("PM");
64
65 delay(1000);
66}
Note: See TracBrowser for help on using the repository browser.