
Descripción.
Este sketch incluye el uso de un sensor (botón de pulsación) y un actuador (LED) nos permite manipular el ambiente de acuerdo a lo percibido.
La tarjeta Arduino es capaz de notar que ha sido presionado el botón (debajo del dedo en la imagen) y esta responde encendiendo el LED. De manera antagónica, cuando el botón es liberado, la tarjeta Arduino apaga el LED.
Implementación.
Hardware.
- En el pin digital 13 se inserta nuevamente el LED.
- El botón se inserta en la protoboard.
- Una de las patas del botón va a Power-5v.
- La otra pata va al pin 7 (entrada – lectura de datos).
- Una resistencia une la segunda pata del botón con la tierra.
Software.
#define LED 13 // Digital PIN for the LED #define BUTTON 7 // Digital PIN for the Button void setup () { pinMode(LED, OUTPUT); // LED pin is output: turn it on/off pinMode(BUTTON, INPUT); // Button pin is input: read it } void loop() { if (digitalRead(BUTTON) == HIGH) // Button is pressed digitalWrite(LED, HIGH); // Turn the LED on else // Button is NOT pressed digitalWrite(LED, LOW); // Turn the LED off }
One Reply to “El segundo sketch: The LED with button”