#include <ezButton.h>
/// constants won't change
ezButton button1(7); // create ezButton object that attach to pin 7;
ezButton button2(8); // create ezButton object that attach to pin 8;
// variables will change:
int ledState1 = LOW; // the current state of LED
int ledState2 = LOW; // the current state of LED
void setup() {
Serial.begin(9600); // initialize serial
pinMode(3, OUTPUT); // set arduino pin to output mode
pinMode(4, OUTPUT); // set arduino pin to output mode
button1.setDebounceTime(50); // set debounce time to 50 milliseconds
button2.setDebounceTime(50); // set debounce time to 50 milliseconds
}
void loop() {
button1.loop(); // MUST call the loop() function first
button2.loop(); // MUST call the loop() function first
if(button1.isPressed()) {
Serial.println("The button is pressed");
// toggle state of LED
ledState1 = !ledState1;
// control LED arccoding to the toggleed sate
digitalWrite(3, ledState1);
}
if(button2.isPressed()) {
Serial.println("The button is pressed");
// toggle state of LED
ledState2 = !ledState2;
// control LED arccoding to the toggleed sate
digitalWrite(4, ledState2);
}
}