LED blink sequence accordingly to array

Hi guys, i am trying to make code which would blink LEDs in the exact sequence as stored in array.

So far i got some examples of arrays, sequences and probably functions but it's all floating as a cloud in my head.

void setup() {

const int ledPins[3] = {2,3,4};
pinMode (ledPins[3], OUTPUT);

const byte sequence[6] = {1,2,3,1,3,2};
const int duration = 400;

 int i;
 int j;
for (i = 0; i < 6; i = i + 1) {
  j = sequence[i] 
  
  digitalWrite(ledPins[j], HIGH);   
  delay(duration);               
  digitalWrite(ledPins[j], LOW);    
  delay(duration); 

}
}

Can you please explain my mistakes

Okay i got my mistake, in const byte sequence[6] = {1,2,0,1,0,2}; should be zeros as reading of array starts from 0. i have hot an error because i have used 3 what is over the array size.

The problem is that Leds don't shine bright enough - I can see a very low light only... but they do blink in sequence.

What value of resistor have you got in series with the LEDs and what colour are they ?

the values of resistors are 220ohm and leds are red,yellow,green (2.1-2.2v)
i have tested them with other codes before as blinker and that was working prefectly

I have just noticed that the code you posted does not compile. Have you posted the correct version ?

That one is missing void loop, here re-posting it full.

void setup() {

const int ledPins[3] = {2,3,4};
pinMode (ledPins[3], OUTPUT);

const byte sequence[6] = {1,2,0,1,0,2};
const int duration = 400;

 int i;
 int j;
for (i = 0; i < 6; i = i + 1) {
  j = sequence[i];
  delay (duration);
  digitalWrite(ledPins[j], HIGH);   
  delay(duration);               
  digitalWrite(ledPins[j], LOW);    
  delay(duration); 

}
}

void loop() {
  // put your main code here, to run repeatedly: 
  
}

Where are the pinMode commands for the 3 output pins ?  pinMode (ledPins[3], OUTPUT);is not it.

Exactly ! bless ya for helping out noobs (me)
pinMode (ledPins[0], OUTPUT);
pinMode (ledPins[1], OUTPUT);
pinMode (ledPins[2], OUTPUT);

Full working code:

void setup() {

const int ledPins[3] = {2,3,4};
pinMode (ledPins[0], OUTPUT);
pinMode (ledPins[1], OUTPUT);
pinMode (ledPins[2], OUTPUT);

const byte sequence[6] = {1,2,0,1,0,2};
const int duration = 400;

 int i;
 int j;
for (i = 0; i < 6; i = i + 1) {
  j = sequence[i];
  delay (duration);
  digitalWrite(ledPins[j], HIGH);   
  delay(duration);               
  digitalWrite(ledPins[j], LOW);    
  delay(duration); 

}
}

void loop() {
  
}

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