Go Down

Topic: How adding delay to a Time type variable (Read 597 times) previous topic - next topic


Apr 03, 2013, 09:26 am Last Edit: Apr 03, 2013, 09:33 am by smo68170 Reason: 1
i want to add a delay to a Time variable to check when the delay is expired but i d'ont know do to this :
Thank's for your help

Time clk;
Time clk2;
int MyHour = 10;
int MyMin = 5;
int MySec =45;
boolean Begin = true;
void loop()
clk =  rtc.getTime(); --> here the date is for exemple 02.04.2013 20:10:20
if ( Begin ==true )
 clk2 = clk + MyHour  +MyMin   +MySec ; --> after that i want the date of clk2 is 03.04.2013 06:06:05
 Begin = false;
if (clk > clk2 )
  //Delay is expired TODo here
  Begin = true;



Apr 03, 2013, 09:29 am Last Edit: Apr 03, 2013, 09:31 am by jzuidema Reason: 1
No clue exactly what you want to do, but couldnt you time a delay by recording and comparing to instances of millis()?

EDIT: I see youre still editing the post. Ill be back in a  minute than


Hi ,
i read that millis()  is cleared every 50 day, it is possible to force it manualy to after my delay  ?


Apr 03, 2013, 09:39 am Last Edit: Apr 03, 2013, 09:52 am by jzuidema Reason: 1
No not that Im aware of, unless you can employ a manual reset of the Arduino, but im not even sure if that will reset the millis function. Of course, the maximum number is known, so if the second number is smaller than the first, you could still calculate the delay. Or take care of it if youre running out of millis().

But it will eventually rollover yes. 50 days is not enough for your intentions?

EDIT: Its 49 days :). But look here, I think youre answer might be in it:


Important question is whether you really need a 'date' type of time keeping, or a general delay which can be kept with millis(). So, simply time passed, or the actual day/month etc as well?


i read that millis()  is cleared every 50 day, it is possible to force it manualy to after my delay  ?

As the link explains, as long as you subtract the previous time from millis() there is no problem with rollover.

What is the longest delay are you trying to implement ?
If this is for an alarm clock type of delay then you would be better comparing the date/time from the RTC with your required end time
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up