I had seen traffic light projects all over the internet for a long time. They are great programs, but they all seem to simulate the European traffic lights.
Well, I thought about it a litte, :-/ , and decided to make a set of US traffic lights for a change.
It took a couple hours, but Here It Is..... without pedestrian cross buttons of course.
This is set up to simulate both the North/South lights and the East/West lights. Just connect 2 of each light to an output and place them on opposite sides of the pole.
I will try and put together an actual traffic light sometime and show you the whole thing in action. Haven't ever created an internet video before, so I need to figure everything out.
Hope everyone likes it.
Dan
Fritz BB:
Code:
/* real_us_traffic_lights2.pde
By: Daniel Wright
2010.JAN.30
I kept seeing all these Traffic Light programs on the internet
and I was real unhappy that they were all European style.
No one had made a US Traffic light. Well, Here it is!
Realistic US Traffic Lights without cross walk buttons.
I am going to work on a model with the Pedestrian cross walk
buttons next.
*/
int carRed1 = 12; // assign the car1 lights
int carYellow1 = 11;
int carGreen1 = 10;
int carRed2 = 9; // assign the car2 lights
int carYellow2 = 8;
int carGreen2 = 7;
int pedRed1 = 6; // assign the pedestrian1 lights
int pedGreen1 = 5;
int pedRed2 = 4; // assign the pedestrian2 lights
int pedGreen2 = 3;
int crossTime = 10000; // time allowed to cross
void setup() {
pinMode(carRed1, OUTPUT);
pinMode(carYellow1, OUTPUT);
pinMode(carGreen1, OUTPUT);
pinMode(pedRed1, OUTPUT);
pinMode(pedGreen1, OUTPUT);
pinMode(carRed2, OUTPUT);
pinMode(carYellow2, OUTPUT);
pinMode(carGreen2, OUTPUT);
pinMode(pedRed2, OUTPUT);
pinMode(pedGreen2, OUTPUT);
// initialize the lights
digitalWrite(carGreen1, HIGH);
digitalWrite(carRed2, HIGH);
digitalWrite(pedGreen1, HIGH);
digitalWrite(pedRed2, HIGH);
}
void loop() {
delay(crossTime); // wait for preset time period
digitalWrite(pedGreen1, LOW); //Turn ped green 1 off
// flash the ped red 1
for (int x=0; x<10; x++) {
digitalWrite(pedRed1, HIGH);
delay(250);
digitalWrite(pedRed1, LOW);
delay(250);
}
digitalWrite(carGreen1, LOW); // car green 1 off
digitalWrite(carYellow1, HIGH); // car yellow 1 on
// flash the ped red 1
for (int x=0; x<10; x++) {
digitalWrite(pedRed1, HIGH);
delay(250);
digitalWrite(pedRed1, LOW);
delay(250);
}
digitalWrite(pedRed1, HIGH); // ped red 1 on
delay(2000); // wait 2 seconds
digitalWrite(carYellow1, LOW); // car yellow 1 off
digitalWrite(carRed1, HIGH); // car red 1 on
delay(1000); // wait 1 second till its safe
digitalWrite(pedRed2, LOW); // ped red 2 off
digitalWrite(carRed2, LOW); // car red 2 off
digitalWrite(pedGreen2, HIGH); // ped green 2 on
digitalWrite(carGreen2, HIGH); // car green 2 on
delay(crossTime); // wait for preset time period
digitalWrite(pedGreen2, LOW);
// flash the ped red 2
for (int x=0; x<10; x++) {
digitalWrite(pedRed2, HIGH);
delay(250);
digitalWrite(pedRed2, LOW);
delay(250);
}
digitalWrite(carGreen2, LOW); // car green 2 off
digitalWrite(carYellow2, HIGH); // car yellow 2 on
// flash the ped red 2
for (int x=0; x<10; x++) {
digitalWrite(pedRed2, HIGH);
delay(250);
digitalWrite(pedRed2, LOW);
delay(250);
}
digitalWrite(pedRed2, HIGH); // ped red 2 on
delay(2000); // wait 2 seconds
digitalWrite(carYellow2, LOW); // car yellow 2 off
digitalWrite(carRed2, HIGH); // car red 2 on
delay(1000); // wait 1 second till its safe
digitalWrite(pedGreen2, LOW); //ped green 2 off
digitalWrite(pedRed1, LOW); //ped red 1 off
digitalWrite(carRed1, LOW); //car red 1 off
digitalWrite(pedGreen1, HIGH); // ped green 1 on
digitalWrite(carGreen1, HIGH); //car green 1 on
}