sleemanj / DS3231_Simple

An Arduino Library for EASY communication with DS3231 I2C RTC Clock and Atmel AT24C32 I2C EEPROM commonly found on the same board. Implements setting, getting the time/date, setting, checking and clearing alarms, and dead-easy circular-buffered logging of data with timestamp.
MIT License
82 stars 25 forks source link

Is running? #6

Open JoseCintra opened 6 years ago

JoseCintra commented 6 years ago

Hi! Which method should I use to know: 1) first time i ran and the device wasn't running yet 2) the battery on the device is low or even missing Some libraries have the method "isrunning" or "lostPower"...

Thanks

geologic commented 6 years ago

For the 1) question: check year, if it is 00, it was powered for the first time:

DateTime MyTimestamp;
  MyTimestamp = Clock.read();
  if (MyTimestamp.Year==00) {
    Clock.promptForTimeAndDate(Serial);
  } else {  
    Serial.print(F(" * RTC time: "));
    Clock.printTo(Serial);  
  }