Pages: [1]   Go Down
Author Topic: MsTimer2 - Calling set() more than once  (Read 617 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: