long time

how to creed very long times, 24 hours

Hedalen:
how to creed very long times, 24 hours

short numHours = 24;

Now, what was your real question?

You need to explain the context. Also what did you mean to type instead of "creed".

The Arduino's timekeeping is not good enough for long periods and you may need to get a Real Time Clock (RTC) module if you want to work with clock time.

...R

Robin2:
You need to explain the context. Also what did you mean to type instead of "creed".

The Arduino's timekeeping is not good enough for long periods and you may need to get a Real Time Clock (RTC) module if you want to work with clock time.

...R

i ment to create a long waiting time, f.e. 24 hours

sorry for my bad English

Hedalen:
i ment to create a long waiting time, f.e. 24 hours

Do you plan to use an RTC module?

...R

Unsigned long can hold 86400000 milliseconds

surepic:
Unsigned long can hold 86400000 milliseconds

Punch 2^32 into your calculator for the correct answer.

I had a hard time inserting the "more than the needed" too. :wink:

86400000 = 24 * 60 * 60 * 1000

And the "correct answer" is off by one.

@gfvalvo And what you got? Unsigned long can hold ~4.2billion. Milliseconds in a day 86.4million.

Isnt 86.4M going to fit in space with storage of 4.2B?

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();
}

thank you all, gonna try first with the RTC

#define SECOND 1000L
#define MINUTE (60 * SECOND)
#define HOUR (60 * MINUTE)
#define DAY (24 * HOUR)

....

if (millis() - last_timestamp >= DAY)
{
  last_timestamp += DAY ;
  do_something ();
}