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

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

1.7.11に対応.

File size: 1.7 KB
Line 
1/*********************************************************************************************************************************************************************************
2* This sketch demonstrates how configure alarm in polled mode.
3 In this mode you hav to check continuously ALARM0 flag in the main program code.
4
5 NOTE: 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#include <RTCInt.h>
12
13RTCInt rtc;
14
15void setup()
16{
17 Serial.begin(9600); //serial communication initializing
18 pinMode(13,OUTPUT);
19 rtc.begin(TIME_H24); //RTC initializing with 24 hour representation mode
20 rtc.setTime(17,0,5,0); //setting time (hour minute and second)
21 rtc.setDate(13,8,15); //setting date
22 rtc.enableAlarm(SEC,ALARM_POLLED,NULL); //enabling alarm in polled mode and match on second
23 rtc.time.hour=17;
24 rtc.time.minute=5;
25 rtc.time.second=10; //setting second to match
26 rtc.setAlarm(); //write second in alarm register
27}
28
29void loop()
30{
31
32 digitalWrite(13,HIGH);
33 delay(100);
34 digitalWrite(13,LOW);
35 delay(400);
36
37 if(rtc.alarmMatch()) //when match occurs led on pin 13 blinks ten times
38 {
39 Serial.println("Alarm match!");
40 for(int i=0; i < 10; i++)
41 {
42 digitalWrite(13,HIGH);
43 delay(200);
44 digitalWrite(13,LOW);
45 delay(800);
46 }
47 rtc.alarmClearFlag(); //clearing alarm flag
48 }
49
50}
Note: See TracBrowser for help on using the repository browser.