// Semáforo
// declarando parametros
int led_verde = 13;
int led_amarillo = 12;
int led_rojo = 11;
const int BOTON = 7; // pin de entrada botón
int state = 0; // estado del boton
void setup() {
// se indica que cada pin es de salidad OUTPUT.
pinMode(led_verde, OUTPUT);
pinMode(led_amarillo, OUTPUT);
pinMode(led_rojo, OUTPUT);
// se apagan todos los LEDs
digitalWrite(led_verde,LOW);
digitalWrite(led_amarillo,LOW);
digitalWrite(led_rojo,LOW);
// se indica que el pin 7 es de entrada INPUT
pinMode(BOTON,INPUT);
// pines 2-5 y 8-10 encienden leds del visualizador de segmentos
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
}
// lazo a ejecutar continuamente una vez cargado el código en el arduino
void loop(){
digitalWrite(led_verde,HIGH); // encender LED verde
//pedestriaBoton(); // se llama a una subrutina
delay(5000);
digitalWrite(led_verde,LOW); // apagar LED verde
digitalWrite(led_amarillo,HIGH); // encender LED amarillo
delay(1000); // mantener por 1 segundos
digitalWrite(led_amarillo,LOW); // apagar LED verde
digitalWrite(led_rojo,HIGH); // encender LED rojo
for(int i=9;i>-1; i--){
funcNum(i);
delay(1000);
}
digitalWrite(led_rojo,LOW);
}
void funcNum(int x){
switch (x){
case 0://when count value is zero show”0” on disp
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
break;
case 1:// when count value is 1 show”1” on disp
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
break;
case 2:// when count value is 2 show”2” on disp
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
break;
case 3:// when count value is 3 show”3” on disp
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
break;
case 4:// when count value is 4 show”4” on disp
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
break;
case 5:// when count value is 5 show”5” on disp
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
break;
case 6:// when count value is 5 show”5” on disp
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
break;
case 7:// when count value is 5 show”5” on disp
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
break;
case 8:// when count value is 8 show”8” on disp
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
break;
break;
case 9:// when count value is 8 show”8” on disp
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
break;
break;
}
}
No hay comentarios.:
Publicar un comentario