user85752: I want to make LED blink patterns with multiple LEDs with the millis() function. I researched about it but did not find a perfect solution.
I found one blog, but it is using a LED pin number array; I need a solution without an array. Any help will be appreciated.
This is my code which I have written:
const int Button_code_1 = 2;
const int Button_code_2 = 3;
const int Button_code_stop = 4;

const int LED_one = 6;
const int LED_two = 8;
const int LED_three = 10;
const int LED_four = 12;

int buttonState_code_1 = 0;
int buttonState_code_2 = 0;
int buttonState_code_stop = 0;

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

  pinMode(Button_code_1,INPUT);
  pinMode(Button_code_2,INPUT);
  pinMode(Button_code_stop,INPUT);

  pinMode(LED_Button_one,INPUT);
  pinMode(LED_Button_two,INPUT);
  pinMode(LED_Button_three,INPUT);
  pinMode(LED_Button_four,INPUT);
  
  pinMode(LED_one, OUTPUT);
  pinMode(LED_two, OUTPUT);
  pinMode(LED_three, OUTPUT);
  pinMode(LED_four, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

  buttonState_code_1 = digitalRead(Button_code_1);
  Serial.println(buttonState_code_1);
  buttonState_code_2 = digitalRead(Button_code_2);
  Serial.println(buttonState_code_2);
  delay(1000);
  buttonState_code_stop = digitalRead(Button_code_stop);
  
  if(buttonState_code_1==1)
  {
    pattern_one();
  }
  if(buttonState_code_2==1)
  {
    pattern_two();
  }

}

void pattern_one()
{
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, HIGH);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, LOW);
  delay(3000);
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, HIGH);
  delay(3000);
  digitalWrite(LED_one, HIGH);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, LOW);
  delay(3000);
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, HIGH);
  digitalWrite(LED_four, LOW);
  delay(3000);
}

void pattern_two()
{
  digitalWrite(LED_one, HIGH);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, LOW);
  delay(3000);
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, HIGH);
  digitalWrite(LED_four, LOW);
  delay(3000);
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, HIGH);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, LOW);
  delay(3000);
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, HIGH);
  delay(3000);
}

This is my sample code with four LEDs. I have written this code with delay(), so when I want to change the pattern I can't because delay() is blocking the code.
I researched this and found the millis() function as the solution. How can I implement this code using the millis() function?

user37622: This is one of the effects for 3 (sets) of LEDs from my light alarm clock sketch:
void cycleEffect() {

  static unsigned long previousMillis;
  static uint8_t cycleCounter;

  if (millis() - previousMillis > 100) {
    previousMillis = millis();
    digitalWrite(LEDS_CENTRAL_PIN, cycleCounter == 0);
    digitalWrite(LEDS_LEFT_PIN, cycleCounter == 1);
    digitalWrite(LEDS_RIGHT_PIN, cycleCounter == 2);
    cycleCounter++;
    if (cycleCounter == 3) {
      cycleCounter = 0;
    }
  }
}


85752: <p>I want to make LED blink patterns with multiple LEDs with the <code>millis()</code> function. I researched about it but did not find a perfect solution.</p>
<p>I found <a href="https://www.baldengineer.com/arduino-chasing-leds-with-millis.html" rel="nofollow noreferrer">one blog</a>, but it is using a LED pin number array; I need a solution without an array. Any help will be appreciated.</p>
<p>This is my code which I have written:</p>
<pre><code>const int Button_code_1 = 2;
const int Button_code_2 = 3;
const int Button_code_stop = 4;

const int LED_one = 6;
const int LED_two = 8;
const int LED_three = 10;
const int LED_four = 12;

int buttonState_code_1 = 0;
int buttonState_code_2 = 0;
int buttonState_code_stop = 0;

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

  pinMode(Button_code_1,INPUT);
  pinMode(Button_code_2,INPUT);
  pinMode(Button_code_stop,INPUT);

  pinMode(LED_Button_one,INPUT);
  pinMode(LED_Button_two,INPUT);
  pinMode(LED_Button_three,INPUT);
  pinMode(LED_Button_four,INPUT);
  
  pinMode(LED_one, OUTPUT);
  pinMode(LED_two, OUTPUT);
  pinMode(LED_three, OUTPUT);
  pinMode(LED_four, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

  buttonState_code_1 = digitalRead(Button_code_1);
  Serial.println(buttonState_code_1);
  buttonState_code_2 = digitalRead(Button_code_2);
  Serial.println(buttonState_code_2);
  delay(1000);
  buttonState_code_stop = digitalRead(Button_code_stop);
  
  if(buttonState_code_1==1)
  {
    pattern_one();
  }
  if(buttonState_code_2==1)
  {
    pattern_two();
  }

}

void pattern_one()
{
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, HIGH);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, LOW);
  delay(3000);
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, HIGH);
  delay(3000);
  digitalWrite(LED_one, HIGH);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, LOW);
  delay(3000);
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, HIGH);
  digitalWrite(LED_four, LOW);
  delay(3000);
}

void pattern_two()
{
  digitalWrite(LED_one, HIGH);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, LOW);
  delay(3000);
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, HIGH);
  digitalWrite(LED_four, LOW);
  delay(3000);
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, HIGH);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, LOW);
  delay(3000);
  digitalWrite(LED_one, LOW);
  digitalWrite(LED_two, LOW);
  digitalWrite(LED_three, LOW);
  digitalWrite(LED_four, HIGH);
  delay(3000);
}
</code></pre>
<p>This is my sample code with four LEDs. I have written this code with <code>delay()</code>, so when I want to change the pattern I can't because <code>delay()</code> is blocking the code.</p>
<p>I researched this and found the <code>millis()</code> function as the solution. How can I implement this code using the <code>millis()</code> function?</p>
 37622: <p>This is one of the effects for 3 (sets) of LEDs from <a href="https://github.com/JAndrassy/SunriseClock/blob/main/SunriseClock/SunriseClock.ino" rel="nofollow noreferrer">my light alarm clock sketch</a>:</p>
<pre><code>void cycleEffect() {

  static unsigned long previousMillis;
  static uint8_t cycleCounter;

  if (millis() - previousMillis &gt; 100) {
    previousMillis = millis();
    digitalWrite(LEDS_CENTRAL_PIN, cycleCounter == 0);
    digitalWrite(LEDS_LEFT_PIN, cycleCounter == 1);
    digitalWrite(LEDS_RIGHT_PIN, cycleCounter == 2);
    cycleCounter++;
    if (cycleCounter == 3) {
      cycleCounter = 0;
    }
  }
}
</code></pre>
