Blink leds simultaneously

Hi!
Iam trying to make 4 LEDs blink simultaneously and a certain amounts of blinks fr each LED, eg. 1 LED blinks 5 times, 2 LED blinks 7 times and so on, at the same time... I've found an old thread and have been working with the suggested code and I get the LEDs to blink but they blink one by one. Is there a way for it to blink simultaneously and different amount of blinks?

Sorry for my poor english, I did my best trying to explain.

int led1 = 6;
int led2 = 2;
int led3 = 3;
int led4 = 4;
int buttonpin = 8;
bool blinking = false;
int button = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(buttonpin, INPUT);
 
}

void loop()
{

 if(blinking == true) {
  blink1(5, 500); // 5 is number of blinks, blinkTime is the milliseconds in each state from above: int blinkTime = 500;
  blink2(7, 250);
  blink3(2, 750);
  blink4(8, 100);
  }

  
  button=digitalRead(buttonpin);
  Serial.println(button);
if (button==HIGH){
  blinking = true;
 
}
else{
  blinking = false;
}
}

void blink1(int repeats, int time)
{
  for (int i = 0; i < repeats; i++)
  {
    digitalWrite(led1, HIGH);
    delay(time);
    digitalWrite(led1, LOW);
    delay(time);
  }

}
void blink2(int repeats, int time)
{
  for (int i = 0; i < repeats; i++)
  {
    digitalWrite(led2, HIGH);
    delay(time);
    digitalWrite(led2, LOW);
    delay(time);
  }

}
void blink3(int repeats, int time)
{
  for (int i = 0; i < repeats; i++)
  {
    digitalWrite(led3, HIGH);
    delay(time);
    digitalWrite(led3, LOW);
    delay(time);
  }

}
void blink4(int repeats, int time)
{
  for (int i = 0; i < repeats; i++)
  {
    digitalWrite(led4, HIGH);
    delay(time);
    digitalWrite(led4, LOW);
    delay(time);
  }

}

That's because (in my opinion) it's a terrible piece of code. If you want to do multiple things at the same time you should not block the Arduino by doing nothing. And that's what delay() does. So a good practice, don't use delay.

Have a look at Blink without delay and Several things at the same time.

Is there a way for it to blink simultaneously and different amount of blinks?

I am feeling generous, so try this and learn from it

const byte ledPins[] = {10, 11, 12};
const byte NUMBER_OF_LEDS = sizeof(ledPins) / sizeof(ledPins[0]);
unsigned long startTimes[3];
unsigned long periods[] = {300, 301, 302};

void setup()
{
  for (int led = 0; led < NUMBER_OF_LEDS; led++)
  {
    pinMode(ledPins[led], OUTPUT);
  }
}

void loop()
{
  unsigned long currentTime = millis();
  for (int led = 0; led < NUMBER_OF_LEDS; led++)
  {
    if (currentTime - startTimes[led] >= periods[led])
    {
      digitalWrite(ledPins[led], !digitalRead(ledPins[led]));
      startTimes[led] = currentTime;
    }
  }
}

Thank you both! I understand why delays are a bad idea. But I was struggling to come up with something better. But UKHelibob reminded me about timers. Thats the way to go! Thank you for the code! I must look into it deeper later today! It shouldn't be much of a struggle to understand it.

Samfag:
But UKHelibob reminded me about timers.

It's not "timers" in the sense of Timer1 and Timer2 or whatever in a microprocessor sense.

It's just making a note of the clock time now (as reflected by millis() at the moment) and having another look in a short while to see what millis() says the time is at that later moment, and seeing if enough time has passed for you to do something with one or other of the leds.

I found this YouTube video by forum member jasmine2501 very useful.

Robin2 has an excellent thread in project guidance
Demonstration code for several things at the same time