Hi all,
I'm new to the Arduino and even in the beginning I came across a problem I failed to resolve.
While running a completely different sketch, I noticed that the four LEDs I used flashed with different intensity for no apparent reason. Just to make sure that they were not damaged etc. I mixed them and even tried others, but with no result.
So I tried the most basic sketch just to flash them and see what happens:
const int ledPin2 = 2;
const int ledPin3 = 3;
const int ledPin4 = 4;
const int ledPin5 = 5;
void setup()
{
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
}
void loop()
{
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin2, LOW);
delay(50);
digitalWrite(ledPin3, HIGH);
delay(50);
digitalWrite(ledPin3, LOW);
delay(50);
digitalWrite(ledPin4, HIGH);
delay(50);
digitalWrite(ledPin4, LOW);
delay(50);
digitalWrite(ledPin5, HIGH);
delay(50);
digitalWrite(ledPin5, LOW);
delay(50);
}
Running this sketch all four LEDs flashed as expected, all with the same intensity.
So then I tried to write sketch using an array, as I used an array when I first came across the problem:
int ledPins[] = {2, 3, 4, 5};
int index;
void setup()
{
pinMode(ledPins[index], OUTPUT);
}
void loop()
{
for (index = 0; index < 4; index++)
{
digitalWrite(ledPins[index], HIGH);
delay(50);
digitalWrite(ledPins[index], LOW);
delay(50);
}
index = 0;
}
Running this sketch on the same circuit only the first LED (on pin 2) flashes with almost full brightness, the second one is barely noticeable, two others just a little bit brighter.
Just to be sure I tried different LEDs, different colours, all with the same result.
I'm using basic ready-to-go starting kit, with some generic LEDs, breadboard, cables, resistors etc., but it seems that the circuit as such is not the problem. Arduino is powered from USB cable, I'm using four 220Ω resistors.
Is there something I overlooked?