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:
9
 *   + uses debounce for multiple buttons.
10
 *   + reads state of multiple buttons
11
 *   + detects the pressed and released events of multiple buttons
12
 */
13
 
14
#include <ezButton.h>
15
 
16
ezButton button1(6);  // create ezButton object that attach to pin 6;
17
ezButton button2(7);  // create ezButton object that attach to pin 7;
18
ezButton button3(8);  // create ezButton object that attach to pin 8;
19
 
20
void setup() {
21
  Serial.begin(9600);
22
  button1.setDebounceTime(50); // set debounce time to 50 milliseconds
23
  button2.setDebounceTime(50); // set debounce time to 50 milliseconds
24
  button3.setDebounceTime(50); // set debounce time to 50 milliseconds
25
}
26
 
27
void loop() {
28
  button1.loop(); // MUST call the loop() function first
29
  button2.loop(); // MUST call the loop() function first
30
  button3.loop(); // MUST call the loop() function first
31
 
32
  int btn1State = button1.getState();
33
  int btn2State = button2.getState();
34
  int btn3State = button3.getState();
35
  Serial.print("button 1 state: ");
36
  Serial.println(btn1State);
37
  Serial.print("button 2 state: ");
38
  Serial.println(btn2State);
39
  Serial.print("button 3 state: ");
40
  Serial.println(btn3State);
41
 
42
  if(button1.isPressed())
43
    Serial.println("The button 1 is pressed");
44
 
45
  if(button1.isReleased())
46
    Serial.println("The button 1 is released");
47
 
48
  if(button2.isPressed())
49
    Serial.println("The button 2 is pressed");
50
 
51
  if(button2.isReleased())
52
    Serial.println("The button 2 is released");
53
 
54
  if(button3.isPressed())
55
    Serial.println("The button 3 is pressed");
56
 
57
  if(button3.isReleased())
58
    Serial.println("The button 3 is released");
59
}