I need to set an alarm which will trigger 250 days set. I am using the Time.Lib and looking through the document found this:
#define elapsedDays(_time_) ((_time_) / SECS_PER_DAY) // this is number of days since Jan 1 1970
The way I plan to count the days would be to create a variable to initially store the start of the daycount and do something like this
if (elapsedDays () - previouselapsedDays >= 250)
the problem is when i did do this it was not compiling, which lead me to believe I cant just use elapsedDays as I have.
Can anybody shed some light?
You have to provide the argument to elapsedDays()
Altogether, this seems very fragile.
I’d be saving the start date in EEPROM, that way, even if the board is restarted accidentally, you’ll have a reference to the elapsed duration.
It would be a pity to wait 250 days to find you missed a restart !
But do I have to declare the elapsedDays like this:
unsigned long elapsedDays = (time) ((time) / SECS_PER_DAY);
or something to that effect. Am I right in saying the there is no function elapsedDays() in the Time.Lib
I think you want something like this
static unsigned long startDay = elapsedDays(now())
if(elapsedDays(now()) - startDay >=250)
startDay = elapsedDays(now())
The suggestion of getting startDay stored in eeprom is very good.
Thanks for that and yes storing the value to eeprom is a good idea
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.