I am programming effects for an LED cube. The cube and the independent functions are working correctly. The problem occurs when I call turnon_layer
function in a loop. The loop counter is not incremented.
for(i=0; i<4; i++)
{
Serial.println(i);
turnon_layer(1000,i);
}
The Serial monitor shows that i
has a constant value of 0 throughout.
When I call the functions with constants, then the output is as expected.
turnon_layer(1000,0);
turnon_layer(1000,1);
turnon_layer(1000,2);
turnon_layer(1000,3);
My turnon_layer function is :
void turnon_layer(long time, int layer)
{
boolean state = HIGH;
long wait, start = millis();
for(i=0; i<4; i++)
{
if(i!=layer) digitalWrite(levelPin[i], !LOW);
else digitalWrite(levelPin[i], !HIGH);
}
if(time/2<10) wait = time/2;
else wait = 10;
while(millis()-start<time)
{
state = !state;
//Serial.println(state);
//First 8 LEDs
for(i=0;i<2;i++)
for(j=0;j<4;j++)
digitalWrite(ledPin[i][j],state);
//Next 8 LEDs
for(i=2;i<4;i++)
for(j=0;j<4;j++)
digitalWrite(ledPin[i][j],!state);
delay(wait);
}
}
I am using the Arduino IDE.
What is going wrong ? Why ?
setup()
andvoid()
methods as well as any variable declarations at the top? – Marko Feb 14 at 4:25setup()
andloop()
? – Dave Tweed Feb 14 at 4:32i
. – Marko Feb 14 at 6:48i
means a lot to me ;) No pun intended. – Marko Feb 14 at 6:51