09. RTC
The rtc object is a built-in object that provides the RTC alarm function.
Functional overview:
- Provides a function to raise an alarm event at a specified time.
Limitations:
- Only one alarm can be used.
rtc Global Object
Methods()/Properties | Summary | Version | Note |
---|---|---|---|
rtc.setAlarm() | Sets the alarm occurrence time. | ||
rtc.stopAlarm() | Releases the alarm. |
Details
rtc.setAlarm(rtcAlarm[,callback])
Sets the alarm occurrence time.
Executes callback processing when an alarm occurs.
The alarm continues until it is stopped.
This method does not allow multiple simultaneous uses.
If you want to set another time, you need to release it once.
Name | Type | M/O | Summary | Note |
---|---|---|---|---|
rtcAlarm | Object | mandatory | Alarm occurrence time setting hour : {number} Alarm occurrence time [hour] Range: 0 - 23) minute : {number} Alarm occurrence time [minute] Range: 0 - 59 second : {number} Alarm occurrence time [second] Range: 0 - 59 timeout : {number} (*1) | *1: Not use. |
callback() | function | mandatory | Executes callback processing when an alarm occurs. | |
return | undefined | - | - | When an error occurs, an exception is raised. |
rtc.stopAlarm()
Releases the alarm.
Name | Type/Object | M/O | Summary | Note |
---|---|---|---|---|
return | undefined | - | - |
Object Usage Examples
Sample1
This is a sample that generates an alarm.
Gets the current time and raises an RTC alarm 20 seconds after that time.
var MAX_COUNT = 5;
var count = MAX_COUNT;
var set_date;
var rtc_time;
var perAlarm = function() {
rtc.stopAlarm();
count--;
print('alarm: count = ' + count);
set_date = new Date();
print('Now time: ' + set_date.toString());
if(count > 0) {
set_date.setSeconds(set_date.getSeconds() + 20);
rtc_time = {
hour: set_date.getHours(),
minute: set_date.getMinutes(),
second: set_date.getSeconds()
};
rtc.setAlarm(rtc_time, perAlarm);
}
}
perAlarm();
Updated: 2022-10-25