Hello
I just started with Arduino a few days ago . My first project "Traffic Lights" works .
I wanted to take it to a next level by adding a button for pedestrians who wish to cross the road .
This is where I am having troubles . Maby somebody can help me by looking at my code .
int red = 13;
int yellow = 12;
int green = 11;
int redv = 10;
int greenv = 9;
int buttonv =2;
void setup(){
pinMode(red,OUTPUT);
pinMode(yellow,OUTPUT);
pinMode(green,OUTPUT);
pinMode(redv,OUTPUT);
pinMode(greenv,OUTPUT);
pinMode(buttonv,INPUT);
}
void loop(){
changeLights();
delay(500);
}
void changeLights(){
int knop = digitalRead(buttonv);
if (knop == LOW){
digitalWrite(redv,HIGH);
delay(500);
digitalWrite(green,HIGH);
digitalWrite(greenv,LOW);
delay(3000);
digitalWrite(green,LOW);
digitalWrite(yellow,HIGH);
delay(2000);
digitalWrite(green,LOW);
digitalWrite(yellow,LOW);
digitalWrite(red,HIGH);
delay(500);
digitalWrite(redv,LOW);
digitalWrite(greenv,HIGH);
delay(3000);
digitalWrite(redv,HIGH);
digitalWrite(greenv,LOW);
delay(500);
digitalWrite(yellow,LOW);
digitalWrite(red,LOW);
digitalWrite(green,HIGH);
}
else {
digitalWrite(green,HIGH);
digitalWrite(redv,HIGH);
digitalWrite(greenv,LOW);
delay(1000);
digitalWrite(redv,HIGH);
digitalWrite(green,LOW);
digitalWrite(yellow,HIGH);
digitalWrite(greenv,LOW);
delay(2000);
digitalWrite(redv,LOW);
digitalWrite(yellow,LOW);
digitalWrite(red,HIGH);
digitalWrite(greenv,HIGH);
delay(5000);
}
}
Thank you !