I have three funtion which describe the brightness of three LEDs. I want the seconde loop run 1 second after the first one and the third 1 second after the second one. One loop needs approximately 5 seconds. So basically I need to run three loops separated. How is this possible?
Update: So I have this code running which I can compile but does not work:
int LED = 3;
int LED2 =10;
int LED3 = 9;
bool loop1state, loop2state, loop3state; // True if running, false if off
int loop1index, loop2index, loop3index; // Iterator values
int periodIndex = 0; // starting with 0, increasing every 10 ms
void setup()
{
Serial.begin(9600);
}
void loop()
{
// Update loop enablers.
switch(periodIndex)
{
case 0:
loop1state = true;
loop1index = 0;
break;
case 1000:
loop2state = true;
loop2index = 0;
break;
case 1500:
loop3state = true;
loop3index = 0;
break;
case 4000:
periodIndex = 0;
break;
}
if (loop1state)
{
for (loop1index = 0; loop1index<255; loop1index++){
analogWrite(LED,loop1index);
}
loop1state = loop1index < 256;
}
if (loop2state)
{
for(loop2index = 0; loop2index<255; loop2index++)
{
analogWrite(LED2,loop2index);
}
loop2state = loop2index < 256;
}
if (loop3state)
{
for(loop3index = 0; loop3index<255; loop3index++)
{
analogWrite(LED3,loop3index);
}
loop3state = loop3index < 256;
}
delay(10);
}