how to turn on and off sequential blinking using one button

Hi, i'm new to arduino i wanted to combine two codes sequential blinking and one pushbutton that make of and on the LEDs but for me it is not working can anyone combine for me please also if there is much easier way to do i will apreciate it

this one if for the button,

const int button = 6; //button pin, touch to ground as button
const int ledPin = 10;
int buttonState = 0;
boolean toggle = true;

void setup()
{
  pinMode(ledPin, OUTPUT); //LED on pin 13
  pinMode(button, INPUT); //arduino monitor pin state
  digitalWrite(button, HIGH); //enable pullups to make pin 5 high
}

void loop()
{
  buttonState = digitalRead(button);
  if (buttonState == LOW)
  {
    if(toggle)
    {
      digitalWrite(ledPin, HIGH);   // set the LED on
      toggle = !toggle;
    }
    else
    {
      digitalWrite(ledPin, LOW);    // set the LED off
      toggle = !toggle;
    }
  }
  delay(200);  //delay for debounce
}
int timer = 500;           // The higher the number, the slower the timing.
int ledPins[] = {
   7, 6, 5,4, 3,2
};       // an array of pin numbers to which LEDs are attached
int pinCount = 6;           // the number of pins (i.e. the length of the array)

void setup() {
  // the array elements are numbered from 0 to (pinCount - 1).
  // use a for loop to initialize each pin as an output:


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

void loop() {
 

    
  // loop from the lowest pin to the highest:
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    // turn the pin on:
    digitalWrite(ledPins[thisPin], HIGH);
    delay(timer);
    // turn the pin off:
    digitalWrite(ledPins[thisPin], LOW);

  }





 // loop from the highest pin to the lowest:
  for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
    // turn the pin on:
    digitalWrite(ledPins[thisPin], HIGH);
    delay(timer);
    // turn the pin off:
    digitalWrite(ledPins[thisPin], LOW);
  }
  
}

We're here to help, not to do your work. (Unless you want to pay, then we have a section for you.)

Two problems:

  • First is already addressed above. YOU need to learn how to do it :wink:
  • And more code related, code with delays() virtually is unmergeable. Have a look at Blink without delay. After that, don't try to merge the code but start from scratch. MUCH easier that way.

HINT: Get the sequential blinking to work first, then add the control after.ward