forked from AndrewFromMelbourne/IntervalTimerManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
104 lines (74 loc) · 3.12 KB
/
README
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
The IntervalTimerManager library provides a mechanism to have an number of
timer objects that will be actioned at particular intervals. For example a
flashing LED. The timer continually polls the time in milliseconds until one
of the timers needs to be actioned. Once the timer is actioned the next time
to action is set.
To use the library you need to create an IntervalTimerManager object and a
number of interval action objects. The IntervalActionManager is a template.
You need to provide the template with the number of buttons that will be
managed. IntervalTimerManager takes no parameters.
IntervalAction object by default an inactive. To start the actions being
called at the desired interval, the interval action objects must be started
by calling activate().
So to create the IntervalTimerManager for 2 timers the code is
//-------------------------------------------------------------------------
IntervalTimerManager<2> intervalTimerManager;
//-------------------------------------------------------------------------
The IntervalTimerManager can then manage up to 2 IntervalAction objects. The
IntervalAction class by itself doesn't provide any functionality. You need
to create your own class that inherits from IntervalAction and does
something with the action() virtual method. The following example creates
a SerialAction class that prints the time in milliseconds that the action
occured.
//-------------------------------------------------------------------------
class SerialAction
:
public IntervalAction
{
public:
SerialAction(
uint8_t id,
uint32_t interval,
IntervalTimerManagerInterface& itmi)
:
IntervalAction(id, interval, itmi)
{
}
virtual void action();
};
//-------------------------------------------------------------------------
void SerialAction::action()
{
Serial.print("action ");
Serial.print(millis(), DEC);
Serial.println("");
}
//-------------------------------------------------------------------------
IntervalTimerManager<1> serialIntervalManager;
SerialAction a1(0, 1, serialIntervalManager);
//-------------------------------------------------------------------------
void setup()
{
Serial.begin(115200);
Serial.println("Starting Interval Timer Manager Test.");
a1.activate();
}
//-------------------------------------------------------------------------
The constructor for the Interval class takes the following parameters:
uint8_t id
The identifier for the timer. This is usefull if more than one
timer is created using the same class. It allows you to determine
which timer actioned the event.
uint32_t interval
The interval in milliseconds that the action should occur.
IntervalActionManagerInterface& abmi
The iterval action manager itself.
Each of the interval action objects register themselves with the interval
action manager when they are created. The IntervalActionManager needs to
check the time to look for timer events. You need to call the task() method
within loop() as follows:
//-------------------------------------------------------------------------
void loop()
{
serialIntervalManager.task();
}