Why Dimmer?
vanessasun64 opened this issue · 3 comments
I think I'm almost completely understanding how the arrays and loops work. My original code looked like this, but I can't quite figure out the first line under void setup. I have i < 8, which I thought referred to my 9th item in the array, which doesn't make sense for me to write because I only have 3 lights. However, my 3rd light dims significantly when I change this 8 to another number. It returns to full brightness after I restore it to i <8. I would therefore like to clarify the meaning of this part, then, and why one of my lights dim when it's not 8? Thanks!
int ledPins[] = {9,10,11};
void setup() {
for(int i = 0; i < 8; i++){
pinMode(ledPins[i],OUTPUT);
}
}
void loop() {
for(int i = 0; i<= 2;){
digitalWrite(ledPins[i], HIGH);
delay(50);
digitalWrite(ledPins[i], LOW);
delay(50);
digitalWrite(ledPins[i+1], HIGH);
delay(50);
digitalWrite(ledPins[i+1], LOW);
delay(50);
i++;
for(int i = 2; i<=2;){
digitalWrite(ledPins[i], HIGH);
delay(500);
digitalWrite(ledPins[i], LOW);
delay(500);
i++;
}
}
}
It's not clear to me what you're trying to accomplish with this code. Your setup loop will indeed go out of range of your array- so don't do that!
As for the two nested for
loops in loop
, a for
loop is supposed to have three parts in the parenthesis; initialization, condition, and increment. See https://www.arduino.cc/reference/en/language/structure/control-structure/for/ That i++
should be in the parenthesis.
If you see my video in the wiki, it'll show you the intended pattern/effect. Would that help?
ah thanks- your description and the video help. I like the pattern. You still need to fix those for loops :) As for the 8
creating dimness in the LED, there's no discernable reason I can see why that should happen. It should be 3
. Apparently failing to set the pinMode
to OUTPUT
can affect the LED brightness from the Arduino. http://forum.arduino.cc/index.php?topic=27285.0