const int buttonPin = 4;  // Pin del botón
const int ledPin = 18;    // Pin del LED interno de la ESP32
bool ledState = false;  // Estado del LED
void setup() {
  pinMode(buttonPin, INPUT_PULLUP);  // Configurar el botón como entrada con resistencia pull-up
  pinMode(ledPin, OUTPUT);          // Configurar el LED como salida
  digitalWrite(ledPin, LOW);       // Apagar el LED al inicio
  Serial.begin(115200);
}
void loop() {
  int buttonState = digitalRead(buttonPin);  // Leer el estado del botón
  if (buttonState == LOW) {
    // Si el botón está presionado, encender el LED
    if (!ledState) {
      Serial.println("El LED se ha encendido.");
      digitalWrite(ledPin, HIGH);  // Encender el LED
      ledState = true;
    }
  } else {
    // Si el botón no está presionado
    if (ledState) {
      Serial.println("El LED se ha apagado.");
      digitalWrite(ledPin, LOW);   // Apagar el LED
      ledState = false;
    }
    delay(500);
    Serial.println(ledState);
  }
}