Skip to content

Commit 2b2d120

Browse files
Added ButtonArray example
1 parent 9067b20 commit 2b2d120

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ Features
1414

1515
Available Examples
1616
----------------------------
17-
* 01.SingleButton
18-
* 02.SingleButtonEvents
19-
* 03.SingleButtonDebounce
20-
* 04.SingleButtonAll
21-
* 05.MultipleButtonAll
22-
* 06.ButtonCount
17+
* [01.SingleButton](https://arduinogetstarted.com/library/button/example/arduino-single-button)
18+
* [02.SingleButtonEvents](https://arduinogetstarted.com/library/button/example/arduino-single-button-events)
19+
* [03.SingleButtonDebounce](https://arduinogetstarted.com/library/button/example/arduino-single-button-debounce)
20+
* [04.SingleButtonAll](https://arduinogetstarted.com/library/button/example/arduino-single-button-all)
21+
* [05.MultipleButtonAll](https://arduinogetstarted.com/library/button/example/arduino-multiple-button-all)
22+
* [06.ButtonCount](https://arduinogetstarted.com/library/button/example/arduino-button-count)
23+
* [07.ButtonArray](https://arduinogetstarted.com/library/button/example/arduino-button-array)
24+
2325

2426
Available Functions
2527
----------------------------
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Created by ArduinoGetStarted.com
3+
*
4+
* This example code is in the public domain
5+
*
6+
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-button-library
7+
*
8+
* This example shows how to use array of button.
9+
*/
10+
11+
#include <ezButton.h>
12+
13+
const int BUTTON_NUM = 5;
14+
15+
const int BUTTON_1_PIN = 2;
16+
const int BUTTON_2_PIN = 3;
17+
const int BUTTON_3_PIN = 4;
18+
const int BUTTON_4_PIN = 5;
19+
const int BUTTON_5_PIN = 6;
20+
21+
ezButton buttonArray[] = {
22+
ezButton(BUTTON_1_PIN),
23+
ezButton(BUTTON_2_PIN),
24+
ezButton(BUTTON_3_PIN),
25+
ezButton(BUTTON_4_PIN),
26+
ezButton(BUTTON_5_PIN)
27+
};
28+
29+
void setup() {
30+
Serial.begin(9600);
31+
32+
for (byte i = 0; i < BUTTON_NUM; i++) {
33+
buttonArray[i].setDebounceTime(50); // set debounce time to 50 milliseconds
34+
}
35+
}
36+
37+
void loop() {
38+
for (byte i = 0; i < BUTTON_NUM; i++)
39+
buttonArray[i].loop(); // MUST call the loop() function first
40+
41+
for (byte i = 0; i < BUTTON_NUM; i++) {
42+
if (buttonArray[i].isPressed()) {
43+
Serial.print("The button ");
44+
Serial.print(i + 1);
45+
Serial.println(" is pressed");
46+
}
47+
48+
if (buttonArray[i].isReleased()) {
49+
Serial.print("The button ");
50+
Serial.print(i + 1);
51+
Serial.println(" is released");
52+
}
53+
}
54+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ezButton
2-
version=1.0.3
2+
version=1.0.4
33
author=ArduinoGetStarted.com
44
maintainer=ArduinoGetStarted.com (ArduinoGetStarted@gmail.com)
55
sentence=Button library for Arduino

0 commit comments

Comments
 (0)