-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
TrackDualButtonClick.ino
64 lines (47 loc) · 1.37 KB
/
TrackDualButtonClick.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
/////////////////////////////////////////////////////////////////
#include "Button2.h"
/////////////////////////////////////////////////////////////////
#define BUTTON_PIN_1 37
#define BUTTON_PIN_2 38
/////////////////////////////////////////////////////////////////
Button2 button_1, button_2;
unsigned long now = 0;
byte counter = 0;
/////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(115200);
delay(50);
Serial.println("\n\nTrack dual button press & release");
button_1.begin(BUTTON_PIN_1);
button_1.setPressedHandler(pressed);
button_1.setReleasedHandler(released);
button_2.begin(BUTTON_PIN_2);
button_2.setPressedHandler(pressed);
button_2.setReleasedHandler(released);
}
/////////////////////////////////////////////////////////////////
void loop() {
button_1.loop();
button_2.loop();
}
/////////////////////////////////////////////////////////////////
void pressed(Button2& btn) {
counter++;
if (counter == 2) {
now = millis();
Serial.println("now!");
}
}
/////////////////////////////////////////////////////////////////
void released(Button2& btn) {
counter--;
if (counter == 0) {
if (now != 0) {
Serial.print("Pressed for: ");
Serial.print(millis() - now);
Serial.println("ms");
}
now = 0;
}
}
/////////////////////////////////////////////////////////////////