I wrote this for my Arduino Mega 2560:
int LED[14] = { 28,29,30,31,32,33,34,35,36,37,38,39,40,41 } ;
...
... (some other code like setup(), etc. Note:pinmode output for this 14 leds wich pins is defined in
... array named LED[]
...
void intro(){
for(int j=1; j<100; j++ ){
for(int r=1; r<15; r++ ){ digitalWrite(LED[r],HIGH); delay(100); }
delay(100);
for(int r=1; r<15; r++ ){digitalWrite(LED[r],LOW); delay(100);}
delay(100);
}
Serial.print("Pattern started");
delay(1000);
}
So when I run this script, I expect that each LED will light up in the sequence and remain lit until the second loop to turn it off, but I see that when lighting each LED, when lighting the 9th LED, the first 8 LEDs shut off inexplicably and LEDs 9 through 14 light one by one, remaining lit. That I expected but why do the first 8 LEDs shut off before the loop ends and the second loop starts?
for (int r = 0; r < 14; r++)
. first index is zero and the size of the array is 14