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() {
Serial.begin(9600);
// 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);
delay(1000);
Serial.println(ledPinIndex%numLEDs);
delay(2000);
digitalWrite(ledPin[ledPinIndex%numLEDs], LOW);
ledPinIndex++;
}
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.