-
Notifications
You must be signed in to change notification settings - Fork 13.3k
/
Copy pathTickerFunctional.ino
66 lines (50 loc) · 1.2 KB
/
TickerFunctional.ino
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
#include "Arduino.h"
#include "Ticker.h"
#define LED1 2
#define LED2 4
#define LED3 12
#define LED4 14
#define LED5 15
class ExampleClass {
public:
ExampleClass(int pin, int duration)
: _pin(pin), _duration(duration) {
pinMode(_pin, OUTPUT);
_myTicker.attach_ms(_duration,
[this]() {
classBlink();
});
}
int _pin, _duration;
Ticker _myTicker;
void classBlink() {
digitalWrite(_pin, !digitalRead(_pin));
}
};
void staticBlink() {
digitalWrite(LED2, !digitalRead(LED2));
}
void scheduledBlink() {
digitalWrite(LED3, !digitalRead(LED2));
}
void parameterBlink(int p) {
digitalWrite(p, !digitalRead(p));
}
Ticker staticTicker;
Ticker scheduledTicker;
Ticker parameterTicker;
Ticker lambdaTicker;
ExampleClass example(LED1, 100);
void setup() {
pinMode(LED2, OUTPUT);
staticTicker.attach_ms(100, staticBlink);
pinMode(LED3, OUTPUT);
scheduledTicker.attach_ms_scheduled(100, scheduledBlink);
pinMode(LED4, OUTPUT);
parameterTicker.attach_ms(100, parameterBlink, LED4);
pinMode(LED5, OUTPUT);
lambdaTicker.attach_ms(100, []() {
digitalWrite(LED5, !digitalRead(LED5));
});
}
void loop() {}