Arduino Evaluation & code

Arduino evaluation

 

//Projct – traffic light

int carRed =12;
int carYellow =11;
int carGreen =10;
int pedRed =9;
int pedGreen = 8;
int button = 2;
int crossTime = 5000;
unsigned long changeTime;

 

void setup () {

pinMode(carRed, OUTPUT);
pinMode(carYellow, OUTPUT);
pinMode(carGreen, OUTPUT);
pinMode(pedRed, OUTPUT);
pinMode(pedGreen, OUTPUT);
pinMode(button, INPUT);

digitalWrite(carGreen,HIGH);
digitalWrite(pedRed,HIGH);

}

void loop ()

 

{
int state = digitalRead(button);
if(state ==HIGH && (millis() – changeTime) > 5000)
{
changeLight();
}
}

void changeLight() {
digitalWrite(carGreen,LOW);
digitalWrite(carYellow,HIGH);
delay (2000);

digitalWrite(carYellow, LOW);
digitalWrite(carRed, HIGH);
delay(crossTime);

 

for (int x=0; x<10; x++)
{
digitalWrite(pedGreen, HIGH);
delay(250);
digitalWrite(pedGreen, LOW);
delay(250);
}

digitalWrite(pedRed, HIGH);
delay(500);

digitalWrite(carYellow, HIGH);
digitalWrite(carRed, LOW);
delay(1000);
digitalWrite(carGreen, HIGH);
digitalWrite(carYellow,LOW);

changeTime= millis();

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s