-
Notifications
You must be signed in to change notification settings - Fork 458
Expand file tree
/
Copy pathCombi_Buttons_AB_BC.ino
More file actions
60 lines (48 loc) · 1.5 KB
/
Combi_Buttons_AB_BC.ino
File metadata and controls
60 lines (48 loc) · 1.5 KB
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
/*
This example will show that the original buttons will not fire any
high-level events after the combinations of buttons are detected, and their
buttons will generate these events instead. Notice how it is not printing
the low-level (E_TOUCH and E_RELEASE) events to not clutter the display.
See https://github.com/m5stack/M5Stack/blob/master/src/utility/M5Button.h
for complete documentation of buttons and events.
*/
#include <M5Stack.h>
// Shortcuts: the & means it's a reference to the same object
Button& A = M5.BtnA;
Button& B = M5.BtnB;
Button& C = M5.BtnC;
// New buttons, not tied to hardware pins
Button AB = Button(55, 193, 102, 21, true, "BtnAB");
Button BC = Button(161, 193, 102, 21, true, "BtnBC");
void setup() {
M5.begin();
A.off = B.off = C.off = AB.off = BC.off = {BLUE, WHITE, NODRAW};
A.on = B.on = C.on = AB.on = BC.on = {RED, WHITE, NODRAW};
M5.Buttons.draw();
M5.Buttons.addHandler(eventDisplay, E_ALL - E_TOUCH - E_RELEASE);
M5.Buttons.addHandler(buttonDown, E_TOUCH);
M5.Buttons.addHandler(buttonUp, E_RELEASE);
}
void loop() {
M5.update();
}
void buttonDown(Event& e) {
if (A && B && !AB) {
A.cancel();
B.cancel();
AB.fingerDown();
}
if (B && C && !BC) {
B.cancel();
C.cancel();
BC.fingerDown();
}
}
void buttonUp(Event& e) {
if (AB && !(A && B)) AB.fingerUp();
if (BC && !(B && C)) BC.fingerUp();
}
void eventDisplay(Event& e) {
Serial.printf("%-14s %-18s %5d ms\n", e.typeName(), e.objName(),
e.duration);
}