Skip to content

getPowerUp()

Arnd edited this page Dec 11, 2020 · 2 revisions

(MCP7940N only)
This function will return a "DateTime" class representing the datetime when the first power restore after failure occurred. This value is kept until the power failure flag is removed using clearPowerFail(). The MCP7940N does not store the seconds at which the power came back up 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 restoreTime = MCP7940.getPowerDown();
   char inputBuffer[40];
   sprintf(inputBuffer,"Power restored at ????-%02d-%02d %02d:%02d:??",
   restoreTime.month(), restoreTime.day(), restoreTime.hour(), restoreTime.minute());
   Serial.println(inputBuffer);
 } // of if-then a power failure occurred
...
Clone this wiki locally