Can anyone point me to info on how to use multiple countdown timer interrupts on the Arduino. I am using MsTimer2 library currently, but don't see anything that describes multiple timers. Even though I am using MsTime2, I don't mind switching to another method or library.
I want to do a count down to check a condition, if the condition is true, I want to trigger a relay for 30 seconds. I am a little confused because I can find info on multiple interrupts for hardware interrupts but nothing on timers.
Thanks.
Louis
Set the time interval to a common denominator, if one is 100ms and the
other is 1 minute, set the interval for 100ms. Have a static variable
for each thing to be timed, for the 1 minute time init this to 600.
Whenever the timer goes off, do the 100ms function, and subtract 1
from the static variable. If the static variable reaches 0, do the 1
minute function and reset it to 600.
-Josh Jordan
> --
> You received this message because you are subscribed to the Google Groups "NYCResistor:Microcontrollers" group.
> To post to this group, send email to nycresistormi...@googlegroups.com.
> To unsubscribe from this group, send email to nycresistormicrocon...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nycresistormicrocontrollers?hl=en.
>
>
Thanks.
Louis
#include <MsTimer2.h>
int timerCounter1 = 6; //wait 60 sec
int timerCounter2 = 3; //wait 30 sec
void checkTime()
{
if(timerCounter1 > 0)
{
timerCounter--;
}
else
{
doThirtySeconds();
timerCounter1 = 6;
}
}
void setup()
{
MsTimer2::set(10000, checkTime); // 10s period
MsTimer2::start();
}
void loop()
{
}
void doThirtySeconds()
{
if(timerCounter2 > 0)
{
digitalWrite(10,HIGH);
timerCounter2--;
}
else
{
digitalWrite(10,LOW);
timerCounter2 = 3;