I recently breadboarded up a row of ten leds controlled by an UNO. One failed so now it's nine. So I've been playing with this type of thing a bunch lately as a form of mental exercise. I love solving puzzles.
Your sketch looks okay other than it will only run through the pattern once. Which is fine if that's what you want. If it should run over and over it belongs in loop. It is also poor technique with Arduino to use delays like that. Using the chip's clock is preffered.
Here's how I'd take on your problem. (Not tested. Written off the top if my head.)
// first an array of our led pins declared globally
const byte ledPin[] = {2,3,4}; // I don't like to make the variable plural
// how many leds do we have
byte ledCount = sizeof(ledPin) / sizeof(ledPin[0]);
// now the sequence
const byte sequence[] = {1,2,0,1,0,2};
// it will help to know how many elements this array holds
byte sequenceCount = sizeof(sequence) / sizeof(sequence[0]);
// time between changes
const unsigned long duration = 400; // it's best to use unsigned longs with timing variables
// now we're ready to set our pins
void setup(){
for (byte index = 0; index < ledCount; index++)
{
pinMode(ledPin[index], OUTPUT);
}
}
// loop will do all the work and display the sequence repeatedly
void loop(){
// we'll need some variables
static byte pointer = 0; // we'll use this to point to the current sequence
static unsigned long lastChangeTime = 0; // for timing purposes
unsigned long currentTime = millis();
// we'll display all the leds then advance the pointer if it's time to
if (currentTime - lastChangeTime > duration)
{
// we have to remember this time
lastChangeTime = currentTime;
// basically all leds are off except one
for (byte index = 0; index < ledCount; index++)
{
if (index == sequence[pointer]) digitalWrite(ledPin[index], HIGH);
else digitalWrite(ledPin[index], LOW);
}
// now we'll deal with the pointer
// use a programming calculator to see how this works. It's cool.
pointer = ++pointer % sequenceCount; // this will roll the pointer over to display the sequence again
}
}
I haven't compiled or tested this but it should work. Notice that you could add leds or sequences to those arrays and the sketch will adjust because I calculate the array size. The way you've done it with constants means that you would have to edit any for loop that accesses those arrays with the new max value. In mine the only constant I use is 0. When the code gets large a constant can be a magic number or a number with no context. It could be a mystery where 6 comes from rather than sequenceCount which gives the number context.
Does that make sense or am I rambling? LOL