#include <ezButton.h>
ezButton button1(2); // create ezButton object that attach to pin 2;
ezButton button2(3); // create ezButton object that attach to pin 3;
const int led1 = 13;
const int led2 = 12;
void setup() {
Serial.begin(9600);
button1.setDebounceTime(50);
button2.setDebounceTime(50);
button2.setCountMode(COUNT_FALLING);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
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 1 is pressed");
digitalWrite(led1, HIGH);
}
else if(button1.isReleased()){
Serial.println("The button 1 is released");
digitalWrite(led1, LOW);
}
unsigned long count = button2.getCount();
if (count > 1){
button2.resetCount();
}
switch(count){
case 0:
digitalWrite(led2, LOW);
break;
case 1:
digitalWrite(led2, HIGH);
break;
}
}