//Lelah Sari 2313304
// Program LED + Push Button On Off
#include <ezButton.h>
#define DEBOUNCE_TIME 50 // the debounce time in millisecond, increase this time if it still chatters
#define LED_PIN1 19 // ESP32 pin GPIO19, which connected to led
#define LED_PIN2 18 // ESP32 pin GPIO18, which connected to led
ezButton button1(23); // create ezButton object that attach to pin GPIO23;
ezButton button2(22); // create ezButton object that attach to pin GPIO22;
int count=0;
int count2=0;
void setup() {
Serial.begin(9600);
button1.setDebounceTime(DEBOUNCE_TIME); // set debounce time to 50 milliseconds
button2.setDebounceTime(DEBOUNCE_TIME); // set debounce time to 50 milliseconds
pinMode(LED_PIN1, OUTPUT);
pinMode(LED_PIN2, OUTPUT);
}
void loop() {
button1.loop(); // MUST call the loop() function first
button2.loop(); // MUST call the loop() function first
if (button1.isReleased()){
count++;
if(count==1){
Serial.println("LED 1 ON");
digitalWrite(LED_PIN1, HIGH); // turn on LED
}
if(count==2){
Serial.println("LED 1 OFF");
digitalWrite(LED_PIN1, LOW); // turn on LED
count=0;
}
}
if (button2.isReleased()){
count2++;
if(count2==1){
Serial.println("LED 2 ON");
digitalWrite(LED_PIN2, HIGH); // turn on LED
}
if(count2==2){
Serial.println("LED 2 OFF");
digitalWrite(LED_PIN2, LOW); // turn on LED
count2=0;
}
}
}