Skip to content

getPowerDown()

Arnd edited this page Dec 11, 2020 · 3 revisions

(MCP7940N only)
This function will return a "DateTime" class representing the datetime when the first power failure occurred. This value is kept until the power failure flag is removed using clearPowerFail(). The MCP7940N does not store the seconds at which a failure occurred and also does not store the year, these values are set to 0 in the returned class.


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.begin(); // start with compile date-time
 MCP7940.setBattery(true); // enable battery backup mode
 ...
 if (MCP7940.getPowerFail()) {
   DateTime failureTime = MCP7940.getPowerDown();
   char inputBuffer[40];
   sprintf(inputBuffer,"Power failed at ????-%02d-%02d %02d:%02d:??",
   failureTime.month(), failureTime.day(), failureTime.hour(), failureTime.minute());
   Serial.println(inputBuffer);
 } // of if-then a power failure occurred
...
Clone this wiki locally