const int buttonPin = 2; // Pin del botón
const int ledPin = 13; // Pin del LED
bool ledStatus = false; // Estado del LED (apagado inicialmente)
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Configurar el botón como entrada con resistencia pull-up interna
pinMode(ledPin, OUTPUT); // Configurar el LED como salida
digitalWrite(ledPin, LOW); // Apagar el LED al inicio
}
void loop() {
if (digitalRead(buttonPin) == LOW) {
// Botón presionado, cambiar estado del LED
ledStatus = !ledStatus; // Cambiar el estado del LED (encendido/apagado)
digitalWrite(ledPin, ledStatus ? HIGH : LOW); // Encender o apagar el LED según el estado actual
delay(200); // Pequeño retardo para evitar el rebote del botón
}
}