Arduino Traffic Controller using LED & push button

/* Arduino traffic controller using LED & push button 
Created on : 3/5/14
*/
#define lbutton 12 //button for traffic arrival indication on left
#define lred 7
#define lyellow 6
#define lgreen 5
#define rbutton 11 //button for traffic arrival indication on right
#define rred 4
#define ryellow 3
#define rgreen 2
#define yblink 500

boolean trafficl = true;
int tmove= 10000;
int changed=2000;

void setup()
{
pinMode(lbutton,INPUT);
pinMode(lred,OUTPUT);
pinMode(lyellow,OUTPUT);
pinMode(lgreen,OUTPUT);
pinMode(rbutton,INPUT);
pinMode(rred,OUTPUT);
pinMode(ryellow,OUTPUT);
pinMode(rgreen,OUTPUT);

digitalWrite(lred, LOW);
digitalWrite(lyellow, LOW);
digitalWrite(lgreen, HIGH);
digitalWrite(rred, HIGH);
digitalWrite(ryellow, LOW);
digitalWrite(rgreen, LOW);
}

void loop()
{
  if(digitalRead(lbutton)== HIGH)
  {
    if(trafficl != true)
    {
      trafficl=true;
      delay(tmove);
      digitalWrite(rgreen, LOW);
      digitalWrite(ryellow, HIGH);
      delay(changed);
      digitalWrite(ryellow, LOW);
      digitalWrite(rred, HIGH);  
      delay(changed);
      for(int a=0; a < 5; a++)
        {
          digitalWrite(lyellow, LOW);
          delay(yblink);
          digitalWrite(lyellow, HIGH);
          delay(yblink);
        }
      digitalWrite(lyellow, LOW);
      digitalWrite(lred, LOW);
      digitalWrite(lgreen, HIGH);    
    }
  }
  if(digitalRead(rbutton)== HIGH)
  {
    if(trafficl = true)
    {
      trafficl=false;
      delay(tmove);
      digitalWrite(lgreen, LOW);
      digitalWrite(lyellow, HIGH);
      delay(changed);
      delay(changed);
      digitalWrite(lyellow, LOW);
      digitalWrite(lred, HIGH);  
      delay(changed);
      for(int a=0; a < 5; a++)
        {
          digitalWrite(ryellow, LOW);
          delay(yblink);
          digitalWrite(ryellow, HIGH);
          delay(yblink);
        }
      digitalWrite(ryellow, LOW);
      digitalWrite(rred, LOW);
      digitalWrite(rgreen, HIGH);    
    }
  }
}

Comments