How can i differenciate between compile and arduino reset

This question is basically about a programmable clock with a RTC DS3231 i'm making on a project thru screen and encoder, and yeah, i can set it and it gets applied, but since i like to adjust the time using compile time (DATE and TIME), when i hit reset to check if it persists, it applies the last compile time, erasing the time i set previously.
(The entire project code is huge) The RTC setup void is basically this:

(...)
//This goes before setup()
  /* RTC */
  #include <Wire.h>
  #include "Adafruit_BusIO_Register.h"
  #include "RTClib.h"
  RTC_DS3231 rtc;
  //time values
  int mins, hh, dd, mm, yy;
  (...)

  void rtcsetup()  //This gets called on setup(), like a normal piece of code
  {
    rtc.begin();
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
  (...)

I was thinking about something that could tell when compile time has changed or not, something like this?)

void rtcsetup()
{
  rtc.begin();
  if(__DATE__ || __TIME__){rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));}
  else;
}

Of course it doesn't work, but that was an idea i had, maybe using the eeprom to save at least the minute of the compile time, and compare if it has changed everytime arduino starts?

You should just not rely solely on DATE and TIME to update the RTC. Provide a user interface to do so, where possibly selecting the compile time info is an option.

1 Like

[quote="coddyhere, post:1, topic:1139574"]
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
Comment this line after you have set the RTC and it will remember that the time is what was set the last time plus passing time since then if you have a battery in it.

How about using EEPROM ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.