Your code followed a simple logic that was very repetitive and could be reduced quite a bit, here's how i would do it.
#define button 1
byte ledOn = 0;
byte led_Array[5] = {13, 11, 9, 7, 5};
byte direction = 13;
byte lock = 0;
byte prevLock = 0;
void setup()
{
pinMode(button, INPUT);
for (int i = 0; i < 4; i++) {
pinMode(led_Array[i], OUTPUT);
digitalWrite(led_Array[i], LOW);
}
}
void loop()
{
if (digitalRead(button) == LOW) {
direction = 13;
lock = 1;
}
else {
direction = 5;
lock = 2;
}
blink();
}
void blink() {
// sort array order, only needs to run once each button press
if (lock != prevLock) {
byte direct = direction;
for (int i = 0; i < 4; i++) {
led_Array[i] = direct;
if (direction == 13) {
direct -= 2;
}
else {
direct += 2;
}
}
prevLock = lock;
}
// blink sequence
digitalWrite(led_Array[ledOn], HIGH);
delay(200);
digitalWrite(led_Array[ledOn], LOW);
if (ledOn < 4) {
ledOn++;
}
else {
ledOn = 0;
}
}