// Definimos el pin del LED
const int ledPin = 2;
// Definimos el pin del botón
const int buttonPin = 4;
// Variable para almacenar el estado actual del botón
int buttonState = HIGH;
void setup() {
// Configuramos el pin del LED como salida
pinMode(ledPin, OUTPUT);
// Configuramos el pin del botón como entrada
pinMode(buttonPin, INPUT);
}
void loop() {
// Leemos el estado del botón
buttonState = digitalRead(buttonPin);
// Si el botón está presionado (LOW)
if (buttonState == HIGH) {
// Encendemos el LED
digitalWrite(ledPin, HIGH);
} else {
// Si el botón no está presionado (HIGH)
// Apagamos el LED
digitalWrite(ledPin, LOW);
}
}