Paso 2: Codificación: después de cargar el sketch, presione el botón y el LED estará encendido. Si es suelta, LED se desactivará.
//Push Buttonconst int buttonPin = 2; //The Button Pin const int ledPin = 13; //The LED Pin int buttonState = 0; //To store the state of the button void setup() { pinMode(ledPin, OUTPUT); //Set the LED Pin to be output pinMode(buttonPin, INPUT); //Set the button Pin to be input } void loop(){ buttonState = digitalRead(buttonPin); //read the state of the button // If the button is pressed, the button state will be HIGH if (buttonState == HIGH) { digitalWrite(ledPin, HIGH); // If button state is HIGH, then turn on LED } else { digitalWrite(ledPin, LOW); // If button state is LOW, then turn off LED } }