Pages: [1]   Go Down
Author Topic: How adding delay to a Time type variable  (Read 552 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
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
Sébastien

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

}
« Last Edit: April 03, 2013, 02:33:31 am by smo68170 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: April 03, 2013, 02:31:23 am by jzuidema » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley. But look here, I think youre answer might be in it:

http://www.cmiyc.com/blog/2012/07/16/arduino-how-do-you-reset-millis/

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?
« Last Edit: April 03, 2013, 02:52:14 am by jzuidema » Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4302
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank's a lot for your reply,
I will do my program with the millis() fonction.
Seb
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4302
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I still think that you would be better to use the time from the RTC and compare your delay end time with it if the delay is going to be longer than one second.  Apart from anything else it will be more accurate.

Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Pages: [1]   Go Up
Jump to: