Subversion Repositories ESP8266_P1_Meter

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 raymond 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
}