-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
M5StackCore2CustomHandler.ino
98 lines (83 loc) · 2.14 KB
/
M5StackCore2CustomHandler.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "M5Core2.h"
#include "Button2.h"
/////////////////////////////////////////////////////////////////
Button2 button;
bool cleared = false;
/////////////////////////////////////////////////////////////////
byte myButtonStateHandler() {
return !(M5.BtnA.isPressed());
}
/////////////////////////////////////////////////////////////////
void setup() {
M5.begin();
button.setDoubleClickTime(300);
// button.setChangedHandler(changed);
// button.setPressedHandler(pressed);
button.setReleasedHandler(released);
// button.setTapHandler(tap);
button.setClickHandler(click);
button.setLongClickDetectedHandler(longClickDetected);
// button.setLongClickHandler(longClick);
button.setDoubleClickHandler(doubleClick);
button.setTripleClickHandler(tripleClick);
button.setButtonStateFunction(myButtonStateHandler);
button.begin(VIRTUAL_PIN);
M5.Lcd.clear();
M5.Lcd.setTextSize(2);
M5.Lcd.setTextWrap(true, true);
M5.Lcd.print("Button A Test");
M5.Lcd.print("\n");
M5.Lcd.print("\n");
}
void loop() {
button.loop();
// clear screen if wrap happened
if (M5.Lcd.getCursorY() <= 16) {
if (!cleared) {
M5.Lcd.clear();
Serial.println("now");
cleared = true;
}
} else {
cleared = false;
}
M5.update();
}
/////////////////////////////////////////////////////////////////
void pressed(Button2& btn) {
M5.Lcd.print("pressed");
M5.Lcd.print("\n");
}
void released(Button2& btn) {
M5.Lcd.print("released: ");
M5.Lcd.print(btn.wasPressedFor());
M5.Lcd.print("\n");
}
void changed(Button2& btn) {
M5.Lcd.print("changed");
M5.Lcd.print("\n");
}
void click(Button2& btn) {
M5.Lcd.print("click");
M5.Lcd.print("\n");
}
void longClickDetected(Button2& btn) {
M5.Lcd.print("long click detected");
M5.Lcd.print("\n");
}
void longClick(Button2& btn) {
M5.Lcd.print("long click");
M5.Lcd.print("\n");
}
void doubleClick(Button2& btn) {
M5.Lcd.print("double click");
M5.Lcd.print("\n");
}
void tripleClick(Button2& btn) {
M5.Lcd.print("triple click\n");
M5.Lcd.print("\n");
}
void tap(Button2& btn) {
M5.Lcd.print("tap");
M5.Lcd.print("\n");
}