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

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

ライブラリを Arduino IDE 1.7.9 にupdate

File size: 1.7 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
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_H24, LOW_POWER); function.
7If 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
14RTCInt rtc; //create an RTCInt type object
15
16
17void 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
34void 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}
Note: See TracBrowser for help on using the repository browser.