I see some bad habits for just starting out programming.
Don't take short cuts in coding, especially at the start.
Make explicit lines of code, comment your sketch so you can come back to it later and easily understand what's going on.
boolean doBlink = false; //used to enable TIMERs
const byte maximum = 5;
const byte LedPins[maximum] = {8, 9, 10, 11, 12};
byte index;
//+1 or -1 for going left and right
char updown = 1;
//timing stuff
unsigned long previousMillis;
unsigned long currentMillis;
unsigned long previous30secondMillis;
//*******************************************************************************
void setup()
{
for (byte x = 0; x < maximum; x++)
{
pinMode(LedPins[x], OUTPUT);
digitalWrite(LedPins[x], LOW);
}
} //END of setup()
//*******************************************************************************
void loop ()
{
unsigned long currentMillis = millis();
//****************************** 5 s e c o n d T I M E R
//if the 5 second TIMER is enabled, has it expired ?
if (doBlink == false && currentMillis - previousMillis >= 5000)
{
//enable the 80ms and 30 second TIMERs
doBlink = true;
//restart the 80ms TIMER
previousMillis = millis();
//restart the 30 second TIMER
previous30secondMillis = millis();
}
//****************************** 8 0 m s T I M E R
//if the 80ms TIMER is enabled, has it expired ?
if (doBlink == true && currentMillis - previousMillis >= 80)
{
//restart the 80ms TIMER
previousMillis = currentMillis;
digitalWrite( LedPins[index], LOW); // turn old led off
index += updown;
digitalWrite(LedPins[index], HIGH); // turn new led on
//are we at the limit ?
if ( index <= 0 || index >= 4)
{
updown = -updown;
}
}
//****************************** 3 0 s e c o n d T I M E R
//if the 30 second TIMER is enabled, has it expired ?
if (doBlink == true && currentMillis - previous30secondMillis > 30000)
{
//LEDs OFF
for (byte x = 0; x < maximum; x++)
{
digitalWrite(LedPins[x], LOW);
}
//enable the 5 second TIMER
doBlink = false;
//restart the 5 second TIMER
previousMillis = millis();
}
} //END of loop()