source: rtos_arduino/trunk/arduino_lib/libraries/RTC/examples/RTC_simple/RTC_simple.ino@ 136

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

ライブラリとOS及びベーシックなサンプルの追加.

File size: 1.8 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**********************************************************************************************************************************************************/
5
6
7
8#include <RTCInt.h>
9
10RTCInt rtc; //create an RTCInt type object
11
12
13void 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
38void 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}
Note: See TracBrowser for help on using the repository browser.