code ignores "if" function for button

Hi, I wrote a programm for a traffic light, but it ignores the "if" line. I tried "LOW" and changing the variables, but the "traffic" part plays regardless of what I'm doing. Can some one help me please

int LED_YELLOW = 13;   //output for yellow led
int LED_RED = 10;      //output for red led
int LED_GREEN = 7;     //output for green led
int BUTTON = 8;        //input for button
int buttonState = 0;   //variable for button state

void setup() {
  pinMode(LED_YELLOW, OUTPUT);
  pinMode(LED_GREEN, OUTPUT);
  pinMode(LED_RED, OUTPUT);
  pinMode(BUTTON, INPUT);
}

void loop() {
  digitalWrite(LED_RED, HIGH);
  digitalWrite(LED_YELLOW, LOW);
  digitalWrite(LED_GREEN, LOW);
  buttonState = digitalRead(BUTTON);
  if (buttonState == HIGH);
    traffic();
  }

  void traffic() {
    delay(5000);
    digitalWrite(LED_YELLOW, LOW);
    delay(1500);
    digitalWrite(LED_RED, LOW);
    digitalWrite(LED_YELLOW, LOW);
    digitalWrite(LED_GREEN, HIGH);
    delay(5000);
    digitalWrite(LED_GREEN, LOW);
    delay(700);
    digitalWrite(LED_GREEN, HIGH);
    delay(700);
    digitalWrite(LED_GREEN, LOW);
    delay(700);
    digitalWrite(LED_GREEN, HIGH);
    delay(700);
    digitalWrite(LED_GREEN, LOW);
    delay(700);
    digitalWrite(LED_GREEN, HIGH);
    delay(700);
    digitalWrite(LED_GREEN, LOW);
    delay(700);
    digitalWrite(LED_GREEN, HIGH);
    delay(700);
    digitalWrite(LED_GREEN, LOW);
    digitalWrite(LED_YELLOW, HIGH);
    delay(1500);
    digitalWrite(LED_YELLOW, LOW);
    digitalWrite(LED_RED, HIGH);
  }
  if (buttonState == HIGH);

means:

  if (buttonState == HIGH) { }
  if (buttonState == HIGH);

Can you find another example that has a semicolon on the end of the if statement?

If you do, it's wrong, too.

Seems to be working. thanks :D :D

nanogamer7:
Seems to be working. thanks :smiley: :smiley:

“Seems,” madam? Nay, it is. I know not “seems.”

.