I would get rid of lot of globals
define all intervals in an array
and let a state machine do the rest
something like
/*
by noiasca
https://forum.arduino.cc/index.php?topic=666044
*/
const uint16_t interval[] {500, 0, 500, 0, 500, 0, 100, 100}; // time to wait in each intervall
const byte ledPinA = 8;
const byte ledPinB = 9;
const byte ledPinC = 10;
//const byte ledPinA = 5; // just for me as I'm using different pins ...
//const byte ledPinB = 6;
//const byte ledPinC = 7;
void handleLeds()
{
static uint32_t previousMillis = 0;
static byte state = 7;
if (millis() - previousMillis >= interval[state])
{
// it's time for next state
state++;
state = state % 8;
Serial.print(F("state=")); Serial.println(state);
// act according state
switch (state)
{
case 0:
digitalWrite(ledPinA, HIGH);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
break;
case 1: // these cases are all the same, so lets spare some lines of codes and combine the cases
case 3:
case 5:
case 7:
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, LOW);
break;
case 2:
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, HIGH);
digitalWrite(ledPinC, LOW);
break;
case 4:
digitalWrite(ledPinA, LOW);
digitalWrite(ledPinB, LOW);
digitalWrite(ledPinC, HIGH);
break;
case 6:
digitalWrite(ledPinA, HIGH);
digitalWrite(ledPinB, HIGH);
digitalWrite(ledPinC, HIGH);
break;
}
previousMillis = millis();
}
}
void setup() {
Serial.begin(115200);
Serial.println(F("\nStart"));
pinMode(ledPinA, OUTPUT);
pinMode(ledPinB, OUTPUT);
pinMode(ledPinC, OUTPUT);
}
void loop() {
handleLeds(); // checks if something is todo with the LEDs
//do other important stuff here
}