Leds not working

Hey!

Im trying to make a traffic light system but something is not working.
The problem is: I want the current green light to turn to yellow when i press the button but it is looping the command even though im not pressing the button.
I dont know why so i was wondering if anyone would help?

const int ledPingreen = 7;
const int ledPinred = 2;
const int ledPinyellow = 8;

const int ledPingreen2 = 13;
const int ledPinred2 = 11;
const int ledPinyellow2 = 12;

const int ledPingreen3 = 3;
const int ledPinred3 = 6;
const int ledPinyellow3 = 5;

const int buttonPin = 4;
const int button2Pin = 9;
const int button3Pin = 10;

int buttonState = 0;
int button2State = 0;
int button3State = 0;
int green2State = 0;

void setup() {
  Serial.begin(9600);
  pinMode(ledPingreen, OUTPUT);
  pinMode(ledPinred, OUTPUT);
  pinMode(ledPinyellow, OUTPUT);
  pinMode(ledPingreen2, OUTPUT);
  pinMode(ledPinred2, OUTPUT);
  pinMode(ledPinyellow2, OUTPUT);
  pinMode(ledPingreen3, OUTPUT);
  pinMode(ledPinred3, OUTPUT);
  pinMode(ledPinyellow3, OUTPUT);
  pinMode(buttonPin, INPUT);
  pinMode(button2Pin, INPUT); 
  pinMode(button3Pin, INPUT);
  //----------------------------------------------------------
  digitalWrite(ledPinred2, HIGH);     
  digitalWrite(ledPinyellow2, LOW);
  digitalWrite(ledPingreen2, LOW); 
  //--------------------------------------------------------------
  digitalWrite(ledPinred, LOW);     
  digitalWrite(ledPinyellow, LOW); 
  digitalWrite(ledPingreen, HIGH);
 //-----------------------------
 digitalWrite(ledPinred3, HIGH);
 digitalWrite(ledPinyellow3, LOW);
 digitalWrite(ledPingreen3, LOW);

}


void loop() {
  
  buttonState = digitalRead(buttonPin);
  button2State = digitalRead(button2Pin);
  button3State = digitalRead(button3Pin);
  green2State = digitalRead(ledPingreen);
  


 if ((button3State = HIGH) && (green2State = HIGH));
 {
   delay(2000);
   //--------------------------------------------------------------
   digitalWrite(ledPinred2, HIGH);     
   digitalWrite(ledPinyellow2, LOW); 
   digitalWrite(ledPingreen2, LOW); 
   //--------------------------------------------------------------
   digitalWrite(ledPinred, LOW);     
   digitalWrite(ledPinyellow, HIGH);
   digitalWrite(ledPingreen, LOW);
   //--------------------------------------------------------------
   delay(2000);
   //--------------------------------------------------------------
   digitalWrite(ledPinred2, HIGH);  
   digitalWrite(ledPinyellow2, LOW);
   digitalWrite(ledPingreen2, LOW); 
   //--------------------------------------------------------------
   digitalWrite(ledPinred, HIGH);    
   digitalWrite(ledPinyellow, LOW);
   digitalWrite(ledPingreen, LOW);  
   //--------------------------------------------------------------
   digitalWrite(ledPingreen3, HIGH);
   digitalWrite(ledPinred3, LOW);
   digitalWrite(ledPinyellow, LOW);
 }
  

}

Thanks!
-Tommy

Please explain exactly what you mean by "something is not working".

if ((button3State = HIGH) &oops

if ((button3State = HIGH) && (green2State = HIGH));
 {

Triple oops, in fact

How are the inputs wired ?

Any pullup-up or pull-down resistors in place or are the pins floating at an unknown voltage when the buttons are not pressed ?

pert:
Please explain exactly what you mean by "something is not working".

The problem is:
When i upload this to the arduino, the actions i put below the "if" will play out even though the button isn't pressed.

See replies #2 & 3.

Compare your code with any "if" in any of the example sketches.

AWOL:
See replies #2 & 3.

Compare your code with any "if" in any of the example sketches.

I dont rlly understand.
srry im very new to this :slight_smile:

I dont rlly understand.

Your code

if ((button3State = HIGH) && (green2State = HIGH));
 {

An example if statement

if (theNumber == 123 && theCharacter == 'X')
{
  //do this
}

Spot the differences

UKHeliBob:
Your code

if ((button3State = HIGH) && (green2State = HIGH));

{




An example if statement


if (theNumber == 123 && theCharacter == 'X')
{
  //do this
}




Spot the differences

Aaaah okay thanks that did it!