Sequential Timed Events

Hi All,

I am new to Arduino programming and I working on a project that will require sequential timed events but I keep getting stuck on programming the events to run at a specific time.

What I need the program to do is:

  1. Move ServoOne 180 degrees
  2. Move ServroTwo 180 degrees
  3. Play an audio file from an SDcard
  4. Stop the audio
  5. Move ServoOne 180 degrees
  6. Move ServroTwo 180 degrees

Can I use the millis function to accomplish this, or is there a better way? I do not want the steps to loop automatically, I want these steps to occur when a button is clicked, after all steps above have been executed, if the button is clicked again, then repeat the same steps.

Thanks

What have you tried? Did you try using delay()?

ab215:
Can I use the millis function to accomplish this, or is there a better way?

It would be easier to use FireTimer.h to handle the creation and management of non-blocking software timers and comes with an example. Basically, you import the lib, setup the timer with a given threshold, and then call "fire()" to see whether or not it's time to change the servo position/play an audio file. You can also change the timeout length in ms or us (you'll probably have to do that for your project).

Here's how you can install it and this explains in more detail on how to use the lib's features.

Power_Broker:
It would be easier to use FireTimer.h to handle the creation and management of non-blocking software timers and comes with an example. Basically, you import the lib, setup the timer with a given threshold, and then call "fire()" to see whether or not it's time to change the servo position/play an audio file. You can also change the timeout length in ms or us (you'll probably have to do that for your project).

I think that might work; I am going to try that.

Thank you!

If the actions really do happen one after the other and if there is NEVER any need to interrupt the sequence then the delay() function would be a perfectly suitable way to manage the timing.

...R

if FireTimer.h works great.

if you want to try BlinkWithoutDelay there are multiple variations.

one is to set the timer...
after 3 seconds.. do this
after 4 seconds.. do that
after 5 seconds.. do the other
reset the timer.

many beginners do it this way :

set a timer, count, do this
create and set a new timer, count, do that
create and set another different timer, count, do the other

and delay() can work for long times.

delay(1);
count++;

if count >= 1000, do this
if count >= 2000, do that
if count >= 2500, stop doing this and stop doing that
if count >= 3000, do the other
if (count >= 4000) {
stop doing the other ;
count = 0 ;
}

it is blocking, but not stopping all progress.
for things like soil moisture where you check every hour and run the water for some time, the 1 second blocking is never a problem and allows you to check temperature and humidity, etc