-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathButton2Integration.ino
52 lines (43 loc) · 1.09 KB
/
Button2Integration.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
// Integration with https://github.com/LennartHennigs/Button2
#include "Modulino.h"
#include "Button2.h"
Button2 button;
ModulinoButtons modulino_buttons;
uint8_t button0StateHandler() {
modulino_buttons.update();
return modulino_buttons.isPressed(0) ? LOW : HIGH; // fake a normal button -> LOW = pressed
}
void handler(Button2& btn) {
switch (btn.getType()) {
case single_click:
break;
case double_click:
Serial.print("double ");
break;
case triple_click:
Serial.print("triple ");
break;
case long_click:
Serial.print("long");
break;
}
Serial.print("click");
Serial.print(" (");
Serial.print(btn.getNumberOfClicks());
Serial.println(")");
}
void setup() {
Serial.begin(115200);
Modulino.begin();
modulino_buttons.begin();
button.setDebounceTime(35);
button.setButtonStateFunction(button0StateHandler);
button.setClickHandler(handler);
button.setDoubleClickHandler(handler);
button.setTripleClickHandler(handler);
button.setLongClickHandler(handler);
button.begin(BTN_VIRTUAL_PIN);
}
void loop() {
button.loop();
}