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

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

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

File size: 1.5 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 24 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_H24); //init RTC in 12 hour mode
17
18 //time settings
19 rtc.setHour(15,0); //setting hour
20 rtc.setMinute(43); //setting minute
21 rtc.setSecond(0); //setting second
22
23
24 rtc.setDay(13); //setting day
25 rtc.setMonth(8); //setting month
26 rtc.setYear(15); //setting year
27
28}
29
30void loop()
31{
32 rtc.getDate(); //getting date in local structure (local_date)
33 rtc.getTime(); //getting time in local structure(local_time)
34
35 //printing date in format YYYY/MM/DD
36 Serial.print(rtc.local_date.year+2000); // year
37 Serial.print('/');
38 Serial.print(rtc.local_date.month); // month
39 Serial.print('/');
40 Serial.print(rtc.local_date.day); // day
41 Serial.print(' ');
42
43 //printing time
44 Serial.print(rtc.local_time.hour); //hour
45 Serial.print(':');
46 Serial.print(rtc.local_time.minute); //minute
47 Serial.print(':');
48 Serial.println(rtc.local_time.second); //second
49
50 delay(1000);
51}
Note: See TracBrowser for help on using the repository browser.