You are on page 1of 1

1

2 #ifndef MILLISTIMER_H
3 #define MILLISTIMER_H
4
5 #if ARDUINO >= 100
6 #include <Arduino.h>
7 #define Constant(x) F(x)
8 #elif defined(WIRING)
9 #include <Wiring.h>
10 #else
11 #include <WProgram.h>
12 #define Constant(x) x
13 #endif
14
15 class MillisTimer;
16 typedef void (*timerEventHandler)(MillisTimer&);
17
18 class MillisTimer
19 {
20 public:
21 MillisTimer(uint32_t interval = 0, timerEventHandler handler = NULL);
22
23 void expiredHandler(timerEventHandler handler);
24 void setInterval(uint32_t interval);
25 void setRepeats(uint32_t repeat); // number of times to repeat, (0) for
indefinitely (default)
26 void setTargetTime(uint32_t targetTime);
27 uint32_t getTargetTime() const;
28 uint32_t getRemainingTime() const;
29 uint32_t getRemainingRepeats() const; // Number of repeats remaining.
30 bool isRunning() const;
31 void stop();
32 void start();
33 void startFrom(uint32_t startTime);
34 void reset();
35 bool expired();
36 void run();
37
38 uint8_t ID;
39
40 private:
41 enum { RUNNING, STOPPED, EXPIRED } m_state;
42
43 uint32_t m_targetTime;
44 uint32_t m_remainingTime;
45 uint32_t m_interval;
46 uint32_t m_repeat;
47 uint32_t m_repeatCount;
48 timerEventHandler cb_onExpired;
49 };
50
51 #endif
52

You might also like