Created
March 9, 2018 04:26
-
-
Save HectorTorres/0ddb3daf69343f3e239c0a0a5f67a20f to your computer and use it in GitHub Desktop.
ArduinoLED.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// declarando parametros | |
int led_1 = 8; //LED 1 al pin digital 8 | |
int led_2 = 12; //LED2 al pin digital 12 | |
int led_3 = 13; //LED 3 al pin digital 13 | |
const int BOTON = 7; // pin de entrada botón | |
int valor = 0; //valor se emplea para almacenar el estado | |
// del botón | |
int estado = 0; // 0 LED apagado, mientras que 1 encendido | |
int viejo_valor = 0; // almacena el antiguo valor | |
// setup de parámetros | |
void setup() { | |
// se indica que cada pin es de salidad OUTPUT. | |
pinMode(led_1, OUTPUT); | |
pinMode(led_2, OUTPUT); | |
pinMode(led_3, OUTPUT); | |
} | |
// lazo a ejecutar continuamente una vez cargado el código en el arduino | |
void loop(){ | |
valor= digitalRead(BOTON); // lee el estado del botón | |
// chequear si el boton esta presionado o no | |
if ((valor == HIGH) && (viejo_valor == LOW)) //Instrucción usada para que el //Arduino reconozca el pulso del botón en el momento justo, y evitar un mal //funcionamiento, debido a la rapidez con que trabaja el Arduino. | |
{ | |
estado=1-estado; // Expresión usada para que cuando estado sea1 el resultado //sea cero, y si estado es cero el resultado sea cero. | |
delay(20); // Retardo de 20 milisegundos utilizado para evitar los rebotes del botón | |
} | |
viejo_valor = valor; // el valor es viejo ahora, hay que almacenarlo | |
if (estado==1){ | |
digitalWrite(led_1,HIGH); // encender LED 1 | |
delay(2000); // mantener por 2 segundos | |
digitalWrite(led_1,LOW); // apagar LED 1 | |
digitalWrite(led_2,HIGH); // encender LED 2 | |
delay(2000); // mantener por 2 segundos | |
digitalWrite(led_2,LOW); // apagar LED 2 | |
digitalWrite(led_3,HIGH); // encender LED 3 | |
delay(2000); // mantener por 2 segundos | |
digitalWrite(led_3,LOW); // apagar LED 3 | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment