/*the aim of this program is to simulate to simultanous
traffic lights each having three colors of green,yellow and red */
/*circutry
the lights anodes are connected to resistors each of one kilo ohm
that are attached to the pins of the resistors 8 through 13 while
the anodes of all lights are connected to the ground*/
/*code
each light is given a number to represent the pin that represents
the pin that it's resistor is connected to*/
int greenone=13;int yellowone=12;int redone=11;int greentwo=10;
int yellowtwo=9;int redtwo=8;
void setup() {// here we tell the arduino to recognize each variable
// for it's according pin
pinMode(greenone, OUTPUT); pinMode(yellowone, OUTPUT);
pinMode(redone, OUTPUT); pinMode(greentwo, OUTPUT);
pinMode(yellowtwo, OUTPUT); pinMode(redtwo, OUTPUT); }
void loop() {
delay(100); // transition time
//phase1: street one is moving while street two is stopped
digitalWrite(redone, LOW);//make sure it is off from the previous cycle
digitalWrite(greentwo, LOW);//make sure it is off from the previous cycle
delay(100);//transition time
digitalWrite(greenone, HIGH);
digitalWrite(redtwo, HIGH);
delay(2400);//the duration of strees one's turn
//phase2: it is now time for street two to move and street one
//to stop so both signals are yellow simulatounsly
digitalWrite(greenone, LOW);
digitalWrite(redtwo, LOW);
delay(100);//transition time
digitalWrite(yellowone, HIGH);
digitalWrite(yellowtwo, HIGH);
delay(1250);//duration of intermediate phase (mutual yellow)
//phase2: street one is stopped while street two is moving
digitalWrite(yellowone, LOW);
digitalWrite(yellowtwo, LOW);
delay(100); //transition time
digitalWrite(redone, HIGH);
digitalWrite(greentwo, HIGH);
delay(2600);}//duration of street two's turn