Skip to content

Commit 4cb4170

Browse files
authored
Merge pull request #5 from IPdotSetAF/2-example-sketch
added example sketch
2 parents 768f294 + a7ff2b7 commit 4cb4170

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

examples/Blink/Blink.ino

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

0 commit comments

Comments
 (0)