Good day, im programming a two way traffic light with two switches..the first switch is to turn on the normal lights settings and take off the normal light settings or the second switch function. the second switch have to take out the normal light and put the two red lights to blink and also take off the lights..however when the first switch is pressed the lights work but pressing the switch back do not take off the lights..same for the second switch..the board needs to be reset in order to take off the lights and then either switch can be pressed....below is the code i used, any suggestions how to fix it will be greatly appreciated...
/buttons
int button1 =2;
int button2 = 3;
// light one
int red1 = 11;
int yellow1 = 12;
int green1 = 7;
// light two
int red2 = 8;
int yellow2 = 9;
int green2 = 10;
void setup(){
// light one
pinMode(red1, OUTPUT);
pinMode(yellow1, OUTPUT);
pinMode(green1, OUTPUT);
// light two
pinMode(red2, OUTPUT);
pinMode(yellow2, OUTPUT);
pinMode(green2, OUTPUT);
//buttons
pinMode ( button1, INPUT);
pinMode ( button2, INPUT) ;
}
void loop(){
if(digitalRead(button1) == HIGH)
for(int thisPin = 7; thisPin<12; thisPin++)
{
digitalWrite(green1, HIGH);
digitalWrite(yellow1, LOW);
digitalWrite(red2, HIGH);
delay(15000);
digitalWrite(red2,HIGH);
digitalWrite(yellow1, HIGH);
digitalWrite(green1,LOW);
delay(3000);
digitalWrite(yellow1,LOW);
digitalWrite(red1,HIGH);
digitalWrite(green2,HIGH);
digitalWrite(red2,LOW);
delay(10000);
digitalWrite(green2,LOW);
digitalWrite(yellow2,HIGH);
digitalWrite(red1,HIGH);
delay(3000);
digitalWrite ( yellow2, LOW);
digitalWrite ( red1, LOW);
}
else
{
(digitalRead(button1) == LOW);
}
if(digitalRead(button2) == HIGH)
for(int thisPin = 11; thisPin =8; thisPin++)
{
digitalWrite(red2,HIGH);
digitalWrite(red1,HIGH);
delay(3000);
digitalWrite(red1,LOW);
digitalWrite(red2,LOW);
delay(3000);
}
else
{
(digitalRead(button2) == LOW);
}
}