How to make sequential led lights up.

Hello, i am a newbie. I want to make LED lights up sequentially every time i push a button.
but my program cause all 3 led to light sequentially. Here is my program.

int timer = 1000;
int ledPins[] = {
5, 6, 7 }; // an array of pin numbers to which LEDs are attached
int pinCount = 3; // the number of pins (i.e. the length of the array)
int button = 8;
int thisPin = 0;
void setup() {

for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
pinMode(button, INPUT);
}

void loop() {
// loop from the lowest pin to the highest:
while(digitalRead(button) == 1);

for (int thisPin = 0; thisPin < pinCount; thisPin++)
{digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);}

}


can anybody help.

I want to make LED lights up sequentially every time i push a button.
but my program cause all 3 led to light sequentially.

So, it does what you want. What is the problem?

No, what i want is every time i push a button , a led will light up. When i depressed, it will be off.
So i need to push a button 3 times for 3 different led to light up. Right now , when i pressed the button , all 3 will light up.

You need to look at the state change detection example to determine when a switch BECOMES pressed, rather than blocking until the switch is pressed. Then, you need to count the number of times the switch is pressed. Light up the appropriate LEDs based on the number of times the switch has been pressed, NOT using a for loop.

I can't check this out, but give it a try:

int ledPins[] = {  5, 6, 7};       // an array of pin numbers to which LEDs are attached

int pinCount = sizeof(ledPins) / sizeof(ledPins[0]);  // Better way to do this

int button = 8;

void setup() {

  for (int thisPin = 0; thisPin < pinCount; thisPin++)  {
    pinMode(ledPins[thisPin], OUTPUT);
  }
  pinMode(button, INPUT);
}

void loop() {
  static long counter = 0L;
  int whichLED;
  
  if (digitalRead(button) == 1) {
    whichLED = counter++ % pinCount;

    switch (whichLED) {
      case 0:
        digitalWrite(pinLed[0], HIGH);
        digitalWrite(pinLed[1], LOW);
        digitalWrite(pinLed[2], LOW);
        break;

      case 1:
        digitalWrite(pinLed[0], LOW);
        digitalWrite(pinLed[1], HIGH);
        digitalWrite(pinLed[2], LOW);
        break;

      case 0:
        digitalWrite(pinLed[0], LOW);
        digitalWrite(pinLed[1], LOW);
        digitalWrite(pinLed[2], HIGH);
        break;
      default:
        break;
    }
  }
}