Problem with Array?

I have a problem with this code. It doesn’t change the six RGB led’s colour within the for loop.
Serial.println show the correct value, which is either LOW or HIGH.

Can someone help me with this problem? And hopefully you understood my problem. :slight_smile:

char *blueLed[] = {"LOW", "HIGH", "HIGH", "HIGH", "LOW", "LOW"};
char *redLed[] = {"HIGH", "LOW", "HIGH", "LOW", "LOW", "HIGH"};
char *greenLed[] = {"HIGH", "HIGH", "LOW", "LOW", "HIGH", "LOW"};

for (int i = 0; i < 6; i++) {
   digitalWrite(blueLed1, (blueLed[i]);
   digitalWrite(redLed1, redLed[i]);
   digitalWrite(greenLed1, greenLed[i]);
   Serial.println(blueLed[i]);

   digitalWrite(blueLed2, blueLed[i]);
   digitalWrite(redLed2, redLed[i]);
   digitalWrite(greenLed2, greenLed[i]);

   digitalWrite(blueLed3, blueLed[i]);
   digitalWrite(redLed3, redLed[i]);
   digitalWrite(greenLed3, greenLed[i]);

   digitalWrite(blueLed4, blueLed[i]);
   digitalWrite(redLed4, redLed[i]);
   digitalWrite(greenLed4, greenLed[i]);

   digitalWrite(blueLed5, blueLed[i]);
   digitalWrite(redLed5, redLed[i]);
   digitalWrite(greenLed5, greenLed[i]);

   digitalWrite(blueLed6, blueLed[i]);
   digitalWrite(redLed6, redLed[i]);
   digitalWrite(greenLed6, greenLed[i]);

   digitalWrite(blueLed6, blueLed[i]);
   digitalWrite(redLed6, redLed[i]);
   digitalWrite(greenLed6, greenLed[i]);
   delay(5000);
   if (i == 6)
   {
      i = 0;
   }
}

remove the quotes. you don't want a string "LOW", you want LOW

… and change the data type to make it a byte array.

HIGH and LOW are integer values, not strings.

byte blueLed[] = {LOW, HIGH, HIGH, HIGH, LOW, LOW};
byte redLed[] = {HIGH, LOW, HIGH, LOW, LOW, HIGH};
byte greenLed[] = {HIGH, HIGH, LOW, LOW, HIGH, LOW};

for (int i = 0; i < 6; i++) {
   digitalWrite(blueLed1, blueLed[i]);
   digitalWrite(redLed1, redLed[i]);
   digitalWrite(greenLed1, greenLed[i]);
   Serial.println(blueLed[i]);
   ...
   ...

You seem to be trying to mess with the for-loop variable to make it loop forever here:

   if (i == 6)
   {
      i = 0;
   }

This isn’t great style and obscures the meaning of the code.

I think you just want to drop the for-loop and let loop do the work:

void loop()
{
  static byte i = 0 ;  // i now global extent as it must exist between calls of loop()

  ..... do the stuff ....

  i = (i+1) % 6 ;  // update i modulo 6
}

And the other observation is you have multiple led pins named blueLed1, blueLed2, etc,
and these are obvious candidates for sticking in an array, and renaming to avoid clashing:

byte blue_led_pins [] = { ..... };
byte green_led_pins [] = { ..... };
byte red_led_pins [] = { ..... };

You can probably then reduce the code in the loop body considerably by inner loops over these
pin arrays.