--Originally published at GTO
I was working with Rodrigo Valdez for the final project, this is a blog post about what we did:
Using an arduino and LED’s we made a traffic light simulator, we choose this project because as engineers we are going to make thing and solve problems of our world so this is something very common in life so we decided to relate something like that to our programming class and simulate the job of that device.
Here is a video of our traffic light working:
Our code is here: (You can modify the timing of the lights by changing the delays)
const int VERDE = 4000;
const int PVERDE = 500;
const int RAMARILLO = 2000;// Conexiones
int verde = 2;
int amarillo = 5;
int rojo = 11;
void setup() {
// Inicialización
digitalWrite(verde,LOW);
digitalWrite(rojo,HIGH);
digitalWrite(amarillo,LOW);pinMode(verde,OUTPUT);
pinMode(amarillo,OUTPUT);
pinMode(rojo,OUTPUT);
}void loop() {
// Secuencia para semaforo 1
digitalWrite(verde,HIGH);
digitalWrite(amarillo,LOW);
digitalWrite(rojo,LOW);
delay(VERDE);
digitalWrite(verde,LOW);
delay(PVERDE);
digitalWrite(verde,HIGH);
delay(PVERDE);
digitalWrite(verde,LOW);
delay(PVERDE);
digitalWrite(verde,HIGH);
delay(PVERDE);
digitalWrite(verde,LOW);
delay(PVERDE);
digitalWrite(verde,HIGH);
delay(PVERDE);
digitalWrite(verde,LOW);
digitalWrite(amarillo,HIGH);
delay(RAMARILLO);
digitalWrite(amarillo,LOW);
digitalWrite(rojo,HIGH);
delay(5000);}