Having a function for long Delay

Hi Guys,

I am new at arduino and i am trying to learn how can I have a delay for long period of time. I also have a PICF8523 RTC module from adafruit.

What I want to know how can I have a simple function, either using mills() or the RTC, to have a delay of 30 minute or 15 minute which I can call in between functions to create this delay.

something like this :

void loop()
{

function_to_do_something ();
delay_function_for_xxxmin/hour();
another_function();

}

Thanks for you help in advance.

Regards
Vishal

delay_function_for_xxxmin/hour();

So, "delay_function_for_xxxmin" is some numeric value and "hour" is a function returning what? The current hour?
The result of the division being what? You don't assign it to anything.

Sorry for that. I actually meant xxxmin or hour by the use of /. Didn't realize it actually meant divide in programing language.

the purpose of the delay_function_for_xxxmin should do nothing for xxx number of minute. Im trying to have a 15 min delay before I execute the next function. I also want to be able to change it to 30min if required.

Doing some research i found out that i can use UL after value of 320000 in delay. However i can see there is a time shift of 5 sec every 10 minute.

I was hoping to have a void function that uses RTC module which creates a delay of 15 minute or 30 minute when called.

Regards
Vishal

TolpuddleSartre:

delay_function_for_xxxmin/hour();

So, “delay_function_for_xxxmin” is some numeric value and “hour” is a function returning what? The current hour?
The result of the division being what? You don’t assign it to anything.

The psuedocode was suggesting that the function would delay for some number of minutes or hours, not that it was dividing anything.

void delayMinutes(int minutesToWaste)
{
   for(int m=0; m<minutesToWaste; m++)
   {
       delay(60 * 1000UL); // waste 60 seconds
   }
}

void delayHours(int hoursToWaste)
{
   for(int h=0; h<hoursToWaste; h++)
   {
      delayMinutes(60);
   }
}

I was hoping to have a void function that uses RTC module which creates a delay of 15 minute or 30 minute when called.

That’s a much different requirement than you stated earlier. Simpler, in some ways. More complicated, in others.

If you are using a library that returns a Unix-time, you can, at the start of the function, get the current time. Then, use a while loop:

   int waitTime = 15;
   while(getUnixTime() - startTime < waitTime*60*1000UL)
   {
       // Twiddle your thumbs doing nothing
   }

This assumes that you used getUnixTime() to populate startTime, and that you write a function called getUnixTime() to return an unsigned long that contains the Unix time.

Both your suggestions seems really promising PaulS.

I will try both you suggestions and get back to you.

Thank you for taking you time out to help me out. Appreciate it alot.

Regards
Vishal