Go Down

Topic: MsTimer2 - Calling set() more than once (Read 1 time) previous topic - next topic


I'm using MsTimer2 to process messages at specific intervals, so I need to call MsTimer2::set() repeatedly so I can set different times. Perhaps this is the wrong library to use for this sort of thing but it's so convenient....

Anyway I found that my process just died when set was called a second time, until I tried calling set with 0 time and 0 funtion  pointer, and it all started working fine!

Here's a snippet:

#include <MsTimer2.h>

unsigned long time;
volatile boolean timerSet=false;

void setup()
 time = 1;

void loop()
   MsTimer2::set(0, 0);
   time+=10;//increase our interval by 10 ms every time (arbitrary hack for demonstration purposes)
   MsTimer2::set(time, DoAction);

void DoAction()
 static boolean output = HIGH;
 digitalWrite(13, output);
 output = !output;
 MsTimer2::stop();//we only want the timer to call once

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131