- Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy path07.ButtonArray.ino
More file actions
Latest commit
54 lines (45 loc) · 1.23 KB
/
Copy path07.ButtonArray.ino
File metadata and controls
54 lines (45 loc) · 1.23 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
/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-button-library
*
* This example shows how to use array of button.
*/
#include<ezButton.h>
constintBUTTON_NUM = 5;
constintBUTTON_1_PIN = 2;
constintBUTTON_2_PIN = 3;
constintBUTTON_3_PIN = 4;
constintBUTTON_4_PIN = 5;
constintBUTTON_5_PIN = 6;
ezButton buttonArray[] = {
ezButton(BUTTON_1_PIN),
ezButton(BUTTON_2_PIN),
ezButton(BUTTON_3_PIN),
ezButton(BUTTON_4_PIN),
ezButton(BUTTON_5_PIN)
};
voidsetup() {
Serial.begin(9600);
for (byte i = 0; i < BUTTON_NUM; i++) {
buttonArray[i].setDebounceTime(50); // set debounce time to 50 milliseconds
}
}
voidloop() {
for (byte i = 0; i < BUTTON_NUM; i++)
buttonArray[i].loop(); // MUST call the loop() function first
for (byte i = 0; i < BUTTON_NUM; i++) {
if (buttonArray[i].isPressed()) {
Serial.print("The button ");
Serial.print(i + 1);
Serial.println(" is pressed");
}
if (buttonArray[i].isReleased()) {
Serial.print("The button ");
Serial.print(i + 1);
Serial.println(" is released");
}
}
}