int button = 2;
int redLED = 13;
int yellowLED = 12;
int greenLED = 11;
int stoppLED = 7; //Ped = pedestrian
int goLED = 6;
int buttonDelay = 1000; //Delay between pushing the button and light changing
int lightDelay = 800; //Delay between switches
int stopTime = 3000; //How long the stop light stays red
void setup() {
// put your setup code here, to run once:
pinMode(button, INPUT);
for (int i = 14; i > 5; i--){
pinMode(i, OUTPUT); //setting up board ports 8-12
}
}
void loop() {
// put your main code here, to run repeatedly:
// digitalRead(button) == LOW is pushed somehow..
//Starting Position
digitalWrite(greenLED, HIGH);
digitalWrite(stoppLED, HIGH);
//When button is pushed
if (digitalRead(button)==LOW){
//Transition from green traffic light to green pedestrian light
delay(buttonDelay);
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, HIGH);
delay(lightDelay);
digitalWrite(yellowLED, LOW);
digitalWrite(stoppLED, LOW);
digitalWrite(redLED, HIGH);
digitalWrite(goLED, HIGH);
delay(stopTime);
//Transition back to green traffic light and red pedestrian light
blinker(goLED, 500, 3);
digitalWrite(goLED, LOW);
digitalWrite(redLED, LOW);
digitalWrite(stoppLED, HIGH);
digitalWrite(greenLED, HIGH);
}
}
//Function for blinking since i didnt feel like writing it a bunch
//of times and now you can customize the blink i guess
void blinker(int led, int interval, int blinks) {
for (int i = 0; i < blinks; i++){
digitalWrite(led, LOW);
delay(interval);
digitalWrite(led, HIGH);
delay(interval);
}
}
Comments