File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < EZButton.h>
2+
3+ #define BTN_1_PIN 6
4+ #define BTN_1 0
5+
6+ void ReadButtons (bool *states, int num) {
7+ // Read all button states however you want
8+ states[BTN_1] = !digitalRead (BTN_1_PIN);
9+ }
10+
11+ EZButton _ezb (1 , ReadButtons, 1000 , 200 );
12+
13+ void setup () {
14+ // initialize pins
15+ pinMode (BTN_1_PIN, INPUT);
16+ pinMode (LED_BUILTIN, OUTPUT);
17+
18+ // subscribe to needed events
19+ _ezb.Subscribe (BTN_1, Btn1Pressed, PRESSED);
20+ _ezb.Subscribe (BTN_1, Btn1Released, RELEASED);
21+ _ezb.Subscribe (BTN_1, Btn1Hold, HOLD);
22+ _ezb.Subscribe (BTN_1, Btn1HoldReleased, HOLD_RELEASED);
23+ }
24+
25+ void loop () {
26+ // EZButton loop
27+ _ezb.Loop ();
28+ }
29+
30+ void Btn1Pressed () {
31+ digitalWrite (LED_BUILTIN, HIGH);
32+ }
33+
34+ void Btn1Released () {
35+ digitalWrite (LED_BUILTIN, LOW);
36+ }
37+
38+ bool state = true ;
39+ void Btn1Hold () {
40+ state = !state;
41+ digitalWrite (LED_BUILTIN, state);
42+ }
43+
44+ void Btn1HoldReleased () {
45+ for (int i = 0 ; i < 6 ; i++) {
46+ state = !state;
47+ digitalWrite (LED_BUILTIN, state);
48+ delay (50 );
49+ }
50+ digitalWrite (LED_BUILTIN, LOW);
51+ }
You can’t perform that action at this time.
0 commit comments