I am making an led bar graph and noticed that one of my LEDs was not well lit (pin 11 specifically) compared to the others my original code is based on a tutorial but looks like this:
int timer = 300;
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13,LOW);
// use a for loop to initialize each pin as an output:
for (int thisPin = 2; thisPin < 11; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 2; thisPin < 11; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = 11; thisPin >= 2; thisPin--) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}
After testing the LED and the voltages on the pins I rechecked the original code and noticed it sets an additional pin (pin 12) as an output but doesn't use it. I adjusted my code to do the same:
int timer = 300;
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13,LOW);
// use a for loop to initialize each pin as an output:
for (int thisPin = 2; thisPin < 12; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 2; thisPin < 11; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = 11; thisPin >= 2; thisPin--) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}
All of the LEDs now look equally bright, my question is: what is the reason for this behavior? I have attached a picture of the circuit, but I am using a 10 segment bar graph and not 10 individual LEDs.
