Hello guys! How can you call a certain function in your program to work after a specific amount of time? Let's say that after a week, that certain function will be called. After another week, it will be called again. Is this possibe with arduinos? Thank you and have a great day
Wall time based or interval based?
Will the Arduino be awake and active during that time or asleep?
All combinations of the above are possible, by the way.
Yes. Look at the blink without delay example. Instead of blinking a led, call your function.
Yes it is possible. The method depends on how accurate the timing must be. Arduino compatible boards have a builtin timer in the millis() function. The blink without delay tutorial show how to use millis() for timing. Be aware that millis() is not real accurate. After a week it could be several minutes off. If more accuracy is required a Real Time Clock (RTC) could be used.
groundFungus:
The blink without delay tutorial show how to use millis() for timing.
I am trying to dig in this blink without delay. There is one thing i cannot figure out. When code gets to the line
if (currentMillis - previousMillis >= interval) {
it gets fired away. After that it waits specified time. Is there a simple way to wait interval time first and then do stuff? Like with SimpleTimer can be done:
t.setTimer(1000, Close1, 1);
zarsss:
I am trying to dig in this blink without delay. There is one thing i cannot figure out. When code gets to the lineif (currentMillis - previousMillis >= interval) {
it gets fired away. After that it waits specified time. Is there a simple way to wait interval time first and then do stuff?
Sure, but now that you hijacked the thread, I can't remember what the original question was. Start your own thread and I am sure you will get lots of help.
Paul
zarsss:
\Is there a simple way to wait interval time first and then do stuff? Like with SimpleTimer can be done:
Yes, that's the delay() function.
It also stops the processor from doing anything else in the meantime.
The final way of starting something after some time (which was the original question, so the hijack is still highly on topic) would be to set a timer interrupt. A technique not recommended before you fully understand how interrupts work.