-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyDelay.h
45 lines (38 loc) · 1015 Bytes
/
MyDelay.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef _MyDelay_h_
#define _MyDelay_h_
#define MYDELAY_REPEAT_FOREVER -1
typedef void (*funTocall)(void);
/**
* Implement a "delay" with the mills() call.
* Must call update method in the main loop
* Must have a delay
* Can have a callback function to be called when timere expires
* Can have a repeat count
*
*/
class myDelay {
public:
myDelay(void);
myDelay(unsigned long dtime);
myDelay(unsigned long dtime, funTocall funcall);
myDelay(unsigned long dtime, funTocall funcall, int repeatCount);
void setDelay(unsigned long);
void setCallback(funTocall);
void setRepeat(int);
bool update();
bool isRunning();
/**
* Start the timer
*/
void start();
void stop();
private:
unsigned long _preMills, _curMills, _delaytime = 0L;
int _initialRepeatCount = MYDELAY_REPEAT_FOREVER;
int _currentRepeatCount = 0;
funTocall _funcall;
bool _useFunction = false;
bool _running = false;
bool _repeating = false;
};
#endif