You could use a timer library, or simply:
const unsigned long oneDay = 86400000;
unsigned long lastRun = 0;
void doEvery24Hours()
{
//The code in this method will only be executed once every 24 hours.
}
void setup()
{
//Whatever
}
void loop()
{
unsigned long millisNow = millis();
if (millisNow - lastRun >= oneDay)
{
lastRun = millisNow;
doEvery24Hours();
}
}
Using a timer like TTimer from TDuino could be implemented as:
#include <TDuino.h>
const unsigned long oneDay = 86400000;
TTimer timer(timerCallback);
void timerCallback(byte timerId)
{
//The code in this method will only be executed once every 24 hours.
}
void setup()
{
timer.setup();
timer.set(oneDay, 0);
}
void loop()
{
timer.loop();
}