Demo entry 6631806

task1

   

Submitted by zl on Jul 19, 2017 at 09:53
Language: C++. Code size: 2.5 kB.

//Zheng leong last updated 18/07/2017

int EW_G = 2 ; //EAST WEST GREEN
int EW_A = 3 ; //EAST WEST AMBER
int EW_R = 4 ; //EAST WEST RED

int NS_R = 5 ; //NORTH SOUTH RED
int NS_A = 6 ; //NORTH SOUTH AMBER
int NS_G = 7 ; //NORTH SOUTH GREEN

int WE_R = 8 ; //WEST EAST RED
int WE_A = 9 ; //WEST EAST AMBER

int BUZZER = 10 ; //BUZZER ALARM

int P_G = 11 ; //PEDESTRIAN GREEN
int P_R = 12 ; //PEDESTRIAN RED

int VEH2 = A0 ; // VEHICLE 2 BUTTON
int PED1 = A1 ; //PEDESTRIAN BUTTON 1
int PED2 = A2 ; //PEDESTRIAN BUTTON 2
int WE_RT = A3 ; // WEST EAST RIGHT TURN
int WE_G = A4 ; //WEST EAST GREEN 
int VEH1 =A5 ; //VEHICLE 1 BUTTON




void setup() {
  //digital pin as an output
  int inMin = 2; // Lowest input pin
int inMax = 13; // Highest input pin
for(int i=inMin; i<=inMax; i++)

  pinMode(i, OUTPUT);
 
  pinMode(A3,OUTPUT);
  pinMode(A4,OUTPUT);
  
  
  pinMode(A0,INPUT);
  pinMode(A1,INPUT);
  pinMode(A2,INPUT);
  pinMode(A5,INPUT);
}

void loop() {

 digitalWrite(NS_G,HIGH); //North South Green to turn right
 digitalWrite(EW_R,HIGH);
 digitalWrite(WE_R,HIGH);
 delay(8000);             //delay for NSG to off
 digitalWrite(NS_G,LOW);  //turn of ns gren to prepare for amber 
 digitalWrite(NS_A,HIGH); //north south amber for turn to right
  delay(2000);             //amber delay
 digitalWrite(NS_A,LOW);  //turn off amber light to prepare for red
 digitalWrite(NS_R,HIGH); //red delay for all
 delay(1000);
 digitalWrite(NS_R,LOW);
 digitalWrite(EW_R,LOW);
 digitalWrite(WE_R,LOW);
 
 digitalWrite(EW_G,HIGH); //turn on ew to allow straight travel
 digitalWrite(WE_G,HIGH);
 digitalWrite(NS_R,HIGH);
 delay(10000);            //delay for EWG to off
 
 
 digitalWrite(EW_G,LOW);
 digitalWrite(EW_A,HIGH);
 delay(2000);              //amber delay
 digitalWrite(EW_A,LOW);
 digitalWrite(EW_R,HIGH);
 delay(1000);             //red delay
 
 
 digitalWrite(WE_RT,HIGH); //west east right turn holding for 4 sec
 delay(4000);
 
 digitalWrite(WE_RT,LOW); //west east right turn blinking
 delay(1000);
 digitalWrite(WE_RT,HIGH);
 delay(1000);
 digitalWrite(WE_RT,LOW);
 delay(1000);
 digitalWrite(WE_RT,HIGH);
 delay(1000);
 digitalWrite(WE_RT,LOW);
 digitalWrite(WE_G,LOW);//turn off green light for WE to change to amber countdown 2 seconds
 digitalWrite(WE_A,HIGH);
 delay(1000);
 digitalWrite(WE_RT,HIGH);
 delay(1000);
 digitalWrite(WE_RT,LOW);
 digitalWrite(WE_A,LOW);
 digitalWrite(WE_R,HIGH);
 delay(1000);
 digitalWrite(NS_R,LOW); //turn off everything
 
 //end of west east right turn
 
 }

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).