int backwardsScan = 0; ... case 3: // KITT-like scanning back and forth 90us/1us // j remembers which LED pair is active // backwardsScan remembers which direction to scan // timer4 handles the 90ms/1ms on-off cycle. // // reset output leds appropriately for (j,timer4): for(int ii=0,ii<=5,ii++){ digitalWrite(ledArray[ii],( (ii==j) && (timer4 <90) } } // update KITT state based on (j,backwardsScan,timer4) if(timer4 > 91){ j += backwardsScan? -1 : 1 ; if (j > 5){ backwardsScan = 1; j = 5; } if (j < 0) { backwardsScan = 0; j = 0; } timer4 = 0; } break;