Hi i'm new to all of this. i have written a programme for my uno but for some reason it doesn't work as i expected. I started with a simple traffic light simulation which worked fine but decided to go a step further and incorporate a crossing however when i press the button it carries on with the standard traffic light loop instead of stopping the loop on red and running the crossing. i know its a problem with the code but not sure where i'm going wrong. This is what code i have got.
int red = 13;
int yellow = 12;
int green = 11;
int redsmall = 10;
int greensmall = 9;
int button = 8;
void setup(){
pinMode (red, OUTPUT);
pinMode (yellow, OUTPUT);
pinMode (green, OUTPUT);
pinMode (redsmall, OUTPUT);
pinMode (greensmall, OUTPUT);
pinMode(button, INPUT);
}
void loop() {
changeLights();
delay(3000);
}
void changeLights(){
digitalWrite (redsmall, HIGH);
digitalWrite (yellow, LOW);
digitalWrite (red, HIGH);
delay (5000);
digitalWrite (yellow, HIGH);
delay (2000);
digitalWrite (yellow, LOW);
digitalWrite (green, HIGH);
digitalWrite (red, LOW);
delay (5000);
digitalWrite (yellow, HIGH);
digitalWrite (green, LOW);
delay (1000);
}
void crossing(){
if (digitalRead) (button = HIGH);
digitalWrite (yellow, HIGH);
digitalWrite (yellow, LOW);
digitalWrite (red, HIGH);
delay (1500);
digitalWrite (redsmall, LOW);
digitalWrite (greensmall, HIGH);
delay (6000);
digitalWrite (greensmall, LOW);
}