I am very new to Arduino, I bought a starter's kit and I am working with the user manual that is available. I am in chapter 6 Tri Color Module

I am using the following code:

// Defining the LED driver pins and some other
// variables.
const int numLEDs = 3;

int blueLEDPin  = 3;
int greenLEDPin = 4;
int redLEDPin   = 5;
int ledPin[3];
int ledPinIndex = 0;

// the setup routine runs once when you press reset:
void setup() {    


  // initialize the digital pin as an output.
  ledPin[0] = blueLEDPin;
  ledPin[1] = greenLEDPin;
  ledPin[2] = redLEDPin;

  for (int i=0; i < numLEDs; i++)
     pinMode(i, OUTPUT);


// the loop routine runs over and over again forever:
void loop() {

  digitalWrite(ledPin[ledPinIndex%numLEDs], HIGH);
  digitalWrite(ledPin[ledPinIndex%numLEDs], LOW);


My problem is that in the setup() method where the following code is

for (int i=0; i < numLEDs; i++)
         pinMode(i, OUTPUT);

From my understanding pinMode OUTPUT is use to send power out of the specific pin. As the code displays pin 3, 4, and 5 are used but the above code is setting pinMode for 0, 1, 2. Is this write? And even if I comment out the two lines up my project no differently as to the previous code.

Can someone verify if the above code is correct, or should it be setting pinMode for 3, 4, and 5.

  • This code is broken. Like a lot of cheap import electronics, it shipped "only half finished" There can still be value if you know what you are getting and are ready to do what was left out, or plan to use things in a different way anyway. – Chris Stratton Aug 6 '16 at 19:29

This line pinMode(i, OUTPUT); should probably be replaced by pinMode(ledPin[i], OUTPUT); Otherwise it won't make sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.