Arduino Challenges

Jack and the Colorful LEDs

Jack connected 6 colorful LEDs to Arduino pins 8, 9, 10, 11, 12 and 13:

He wanted to cycle through the LEDs (turn on a different LED every time, in sequence), and copied a code snippet he found on the internet. However, the snippet he found does not light all the LEDs, and Jack doesn't know how to write Arduino code.

Can you help Jack and fix the snippet he found? Check your solution by clicking the "Run Code" button on top of the code editor.


Have questions? Feedback? Please share with us below:

sketch.ino

byte leds[] = {
  8, 9,
  /* Hmm... Maybe add something here? */
};

void setup() {
  for (byte i = 0; i < sizeof(leds); i++) {
    pinMode(leds[i], OUTPUT);
  }
}

void loop() {
  for (byte i = 0; i < sizeof(leds); i++) {
    digitalWrite(leds[i], HIGH);
    delay(250);
    digitalWrite(leds[i], LOW);
  }
}