Skip to content

setAlarm()

Arnd edited this page Dec 11, 2020 · 4 revisions

SetAlarm(alarmNumber, alarmType, alarmDate [,alarmState])


This function is used to set one of the 2 builtin alarms of the MCP7940. The library will pull the the MFP pin low when the alarm condition is reached, this can either trigger an event or an interrupt or the state of the pin can be queried using the getMFP() function. The pin will remain pulled low until the alarm condition is reset, which can be done by either overwriting the alarm or with the clearAlarm() function, although if the alarm condition remains true when the alarm is cleared it will immediately be re-asserted.

The "alarmState" is an optional parameter which defaults to "true" and specifies if the alarm is to be activated once set.

There are two alarms, numbered 0 and 1. Each alarm can be set to trigger at a specific point in time or when one of the columns matches:

AlarmType Description
0 Alarms off
1 Minutes match
2 Hours match
3 Day-of-Week matches
4 Date matches
7 Seconds, Minutes, Hours, Day-of-Week, Date and Month match

Example:

...
MCP7940_Class MCP7940; // Create an instance of the MCP7940
...
void setup() {
  Serial.begin(SERIAL_SPEED);
  while (!MCP7940.begin()) { // Initialize RTC communications
    Serial.println("Unable to find MCP7940. Checking again in 1 second.");
    delay(1000);
  } // of loop until device is located
 MCP7940.setAlarm(0,7,DateTime(2017,8,5,18,30,0)); // 0 triggers at 18:30:00 on 2017-08-05
 MCP7940.setAlarm(1,2,DateTime(2017,8,5,18,30,0)); // 1 triggers every time the hour is 18
 while (MCP7940.getMFP()); // loop until an alarm is triggered
...
Clone this wiki locally