#include <ezButton.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define BUTTON_PIN 4 // ESP32 pin GPIO4
#define LED_PIN 2 // ESP32 pin GPIO2
LiquidCrystal_I2C lcd(0x27, 16, 2);
ezButton button(BUTTON_PIN);
// variables will change:
int led_state = LOW; // the current state of LED
void setup() {
Serial.begin(9600); // initialize serial
pinMode(LED_PIN, OUTPUT); // set ESP32 pin to output mode
button.setDebounceTime(50); // set debounce time to 50 milliseconds
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Sistema Listo");
Serial.println("Sistema Listo");
}
void loop() {
button.loop(); // MUST call the loop() function first
if (button.isPressed()) {
Serial.println("Press");
led_state = !led_state; // toggle state of LED
if (led_state==1) {
lcd.setCursor(8,1);
lcd.print(" ON ");
}
if (led_state==0) {
lcd.setCursor(8,1);
lcd.print(" OFF ");
}
digitalWrite(LED_PIN, led_state);
}
}