[Solved] LED's blinks anyways

Hey,
I have a prob with the control of 2 LED's...
After a button is pressed, the first LED should glow for 5 sec then the second.
This can be repeated everytime the button is pressed.
But as I uploaded the sketch, the LED's blink anyways.
The first for five second, then the second for five seconds and so on...
Here's my code:

#define STATE_IDLE		0
#define STATE_INIT		1
#define STATE_RUN	        2
#define STATE_EXITING	        3


int Zustand;
int led1 = 2;
int led2 = 3;
int button = 8;

void setup()
{
  Zustand = STATE_IDLE;
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(button, INPUT);
}

void loop()
{
  switch( Zustand )
  {
    case STATE_IDLE: Idle();
    break;
    case STATE_INIT: Init();
    break;
    case STATE_RUN: Run();
    break;
    case STATE_EXITING: Exiting();
    break;
  }
}

void Idle(){
  if (digitalRead(button == HIGH)) { 
    Zustand = STATE_INIT; 
  }
}

void Init()
{
  delay(1000);
  Zustand = STATE_RUN;
}

void Run()
{
  digitalWrite(led1, HIGH);
  digitalWrite(led2, LOW);
  delay(3000);
  digitalWrite(led1, LOW);
  digitalWrite(led2, HIGH);
  delay(3000);
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
}
  
void Exiting()
{
	delay(1000);
	Zustand = STATE_IDLE;
}

I'm sorry for my bad English.
Greeting,
Mathis

Is it possible the button has a floating input? (Is there a pulldown resistor in your wiring?)

Shouldn't Run() set Zustand before it exits?

-br

The state is not updated by the Run() function so once it is STATE_RUN it will not change so it keeps on calling Run() and it goes on for ever.

Thank you for the Answer, but the LED's still blinks (now with my given delay) in a loop, without pressing anything.
Yes I have a pulldown resistor for the button.

  if (digitalRead(button == HIGH)) {

Bracket in wrong place.

...and while you're at it, you should definitely look at "blink without delay" example to replace all those delay()s :wink:

Thank you,
with all your help it works :slight_smile:
[Solved]