Go Down

Topic: US Traffic Lights (Read 3 times) previous topic - next topic

aderbal

#15
Feb 24, 2010, 12:09 am Last Edit: Feb 24, 2010, 12:23 am by aderbal Reason: 1
Hi Wrox and all,

The sketch you wrote, Wrox, works perfectly and is great in that it is easy to understand and modify! I am a beginner and have been looking for a controller of 4lanes. I developed yours into that but could not add a switch that turns on the yellow lights into flashing mode when needed like when it's late at night.

Guys could you please take a look and help me adding that switch?

thanks,

Code: [Select]


/* real_us_traffic_lights2.pde
  By: Daniel Wright
  2010.JAN.30         (Modified by Ayad Derbal 2010.Feb.23)
  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 = 13; // assign the car1 lights
int carYellow1 = 12;
int carGreen1 = 11;
int carRed2 = 10; // assign the car2 lights
int carYellow2 = 9;
int carGreen2 = 8;
int carRed3 = 7; // assign the car3 lights
int carYellow3 = 6;
int carGreen3 = 5;
int carRed4 = 4; // assign the car4 lights
int carYellow4 = 3;
int carGreen4 = 2;

void setup() {
pinMode(carRed1, OUTPUT);
pinMode(carYellow1, OUTPUT);
pinMode(carGreen1, OUTPUT);
pinMode(carRed2, OUTPUT);
pinMode(carYellow2, OUTPUT);
pinMode(carGreen2, OUTPUT);
pinMode(carRed3, OUTPUT);
pinMode(carYellow3, OUTPUT);
pinMode(carGreen3, OUTPUT);
pinMode(carRed4, OUTPUT);
pinMode(carYellow4, OUTPUT);
pinMode(carGreen4, OUTPUT);

// initialize the lights
digitalWrite(carRed1, HIGH);
digitalWrite(carRed2, HIGH);
digitalWrite(carRed3, HIGH);
digitalWrite(carRed4, HIGH);
delay(4000);
}

void loop() {
digitalWrite(carRed1, LOW);
digitalWrite(carYellow1, HIGH);
delay(1500);
digitalWrite(carGreen1, HIGH);
digitalWrite(carYellow1, LOW);
delay(5000);
// flash the ped red 1
for (int x=0; x<6; x++) {
digitalWrite(carYellow1, HIGH);
delay(500);
digitalWrite(carYellow1, LOW);
delay(500);
}
digitalWrite(carGreen1, LOW);
digitalWrite(carYellow1, LOW);
digitalWrite(carRed1, HIGH);

delay(2000); // wait 1 second till its safe

digitalWrite(carRed2, LOW);
digitalWrite(carYellow2, HIGH);
delay(1500);
digitalWrite(carGreen2, HIGH);
digitalWrite(carYellow2, LOW);
delay(5000);
// flash the ped red 1
for (int x=0; x<6; x++) {
digitalWrite(carYellow2, HIGH);
delay(500);
digitalWrite(carYellow2, LOW);
delay(500);
}
digitalWrite(carGreen2, LOW);
digitalWrite(carYellow2, LOW);
digitalWrite(carRed2, HIGH);
delay(2000); // wait 1 second till its safe

digitalWrite(carRed3, LOW);
digitalWrite(carYellow3, HIGH);
delay(1500);
digitalWrite(carGreen3, HIGH);
digitalWrite(carYellow3, LOW);
delay(5000);
// flash the ped red 1
for (int x=0; x<6; x++) {
digitalWrite(carYellow3, HIGH);
delay(500);
digitalWrite(carYellow3, LOW);
delay(500);
}
digitalWrite(carGreen3, LOW);
digitalWrite(carYellow3, LOW);
digitalWrite(carRed3, HIGH);
delay(2000); // wait 1 second till its safe


digitalWrite(carRed4, LOW);
digitalWrite(carYellow4, HIGH);
delay(1500);
digitalWrite(carGreen4, HIGH);
digitalWrite(carYellow4, LOW);
delay(5000);
// flash the ped red 1
for (int x=0; x<6; x++) {
digitalWrite(carYellow4, HIGH);
delay(500);
digitalWrite(carYellow4, LOW);
delay(500);
}
digitalWrite(carGreen4, LOW);
digitalWrite(carYellow4, LOW);
digitalWrite(carRed4, HIGH);
delay(2000); // wait 1 second till its safe
}




Go Up