-
-
Save parzibyte/de204478d4883c24c569a2ad3603e5af 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 2: Semáforo doble | |
INSTRUCCIONES: Realizar un sketch en Arduino | |
que permita encender 6 LED’s con la lógica de | |
dos semáforos con cruce. Uno de ellos encenderá | |
con la lógica normal mientras que el otro se | |
mantiene en ROJO. Cuando el primero encienda el | |
color ROJO, el segundo iniciará ahora el ciclo | |
normal y el primero debe mantenerse en ROJO. | |
@author parzibyte | |
Visita: parzibyte.me/blog | |
*/ | |
int verde1 = 5, amarillo1 = 6, rojo1 = 7, | |
verde2 = 8, amarillo2 = 9, rojo2 = 10, | |
duracionVerdeYRojo = 5, duracionAmarillo = 3; | |
void setup() { | |
for (int x = verde1; x <= rojo2; x++) { | |
pinMode(x, OUTPUT); | |
} | |
} | |
void encenderVerde1() { | |
digitalWrite(verde1, HIGH); | |
} | |
void encenderAmarillo1() { | |
digitalWrite(amarillo1, HIGH); | |
} | |
void encenderRojo1() { | |
digitalWrite(rojo1, HIGH); | |
} | |
void encenderVerde2() { | |
digitalWrite(verde2, HIGH); | |
} | |
void encenderAmarillo2() { | |
digitalWrite(amarillo2, HIGH); | |
} | |
void encenderRojo2() { | |
digitalWrite(rojo2, HIGH); | |
} | |
void apagarTodos() { | |
for (int x = verde1; x <= rojo2; x++) { | |
digitalWrite(x, LOW); | |
} | |
} | |
void apagarLosDel1() { | |
for (int x = verde1; x <= rojo1; x++) { | |
digitalWrite(x, LOW); | |
} | |
} | |
void apagarLosDel2() { | |
for (int x = verde2; x <= rojo2; x++) { | |
digitalWrite(x, LOW); | |
} | |
} | |
int milisegundosAPartirDeSegundos(int segundos) { | |
return segundos * 1000; | |
} | |
void loop() { | |
apagarTodos(); | |
encenderVerde1(); | |
encenderRojo2(); | |
delay(milisegundosAPartirDeSegundos(duracionVerdeYRojo - duracionAmarillo)); | |
apagarLosDel1(); | |
encenderAmarillo1(); | |
delay(milisegundosAPartirDeSegundos(duracionAmarillo)); | |
apagarTodos(); | |
encenderRojo1(); | |
encenderVerde2(); | |
delay(milisegundosAPartirDeSegundos(duracionVerdeYRojo - duracionAmarillo)); | |
apagarLosDel2(); | |
encenderAmarillo2(); | |
delay(milisegundosAPartirDeSegundos(duracionAmarillo)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment