-
-
Save parzibyte/8f915850297c099a45a10c469458cbce to your computer and use it in GitHub Desktop.
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
/* | |
Prueba 1: Semáforo simple | |
INSTRUCCIONES: Realizar un sketch en Arduino que permita | |
encender tres LED’s con la lógica de funcionamiento de un | |
semáforo simple. El proceso inicia con el encendido del VERDE. | |
@author parzibyte | |
Visita: parzibyte.me/blog | |
*/ | |
int ledRojo = 7, | |
ledAmarillo = 8, | |
ledVerde = 9, | |
SEGUNDOS_DE_ESPERA_VERDE_Y_ROJO = 5 * 1000, // En mi caso puse que el verde y rojo duren 10 segundos (10,000 milisegundos) | |
SEGUNDOS_DE_ESPERA_AMARILLO = 2 * 1000, // En mi caso puse que el amarillo dure 2 segundos (2,000 milisegundos) | |
LED_ACTUAL = 0; // Por defecto no hay led encendido | |
void setup() { | |
/* | |
Establecemos como salida los tres leds | |
*/ | |
pinMode(ledRojo, OUTPUT); | |
pinMode(ledAmarillo, OUTPUT); | |
pinMode(ledVerde, OUTPUT); | |
} | |
void loop() { | |
cambiaA(ledVerde); | |
delay(SEGUNDOS_DE_ESPERA_VERDE_Y_ROJO); | |
cambiaA(ledAmarillo); | |
delay(SEGUNDOS_DE_ESPERA_AMARILLO); | |
cambiaA(ledRojo); | |
delay(SEGUNDOS_DE_ESPERA_VERDE_Y_ROJO); | |
} | |
void cambiaA(int nuevoLed) { | |
/* | |
Función ayudante que apaga el led y enciende el nuevo, | |
además de asignar a LED_ACTUAL el valor del (valga la redundancia) | |
led actual | |
*/ | |
if(LED_ACTUAL != 0) digitalWrite(LED_ACTUAL, LOW); | |
LED_ACTUAL = nuevoLed; | |
digitalWrite(LED_ACTUAL, HIGH); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment