int ledPin = 23; // Pin del LED
int buttonPin = 22; // Pin del botón
bool ledState = LOW; // Estado actual del LED
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop(){
int buttonState = digitalRead(buttonPin);
if (buttonState == LOW){
ledState = !ledState; // Invierte el estado del LED
digitalWrite(ledPin, ledState);
while (digitalRead(buttonPin) == LOW); //Espera a que se suelte el botón
}
}