I have a project that requires eight DIFFERENT lights to cycle between on and off at random times with random fade in, random fade out and random on/off durations. My strategy is to fade on, leave on for a random time, fade off, leave off for a random time, repeat. While right now I've got a random pin selected before each for loop, I'd like to use a for-loop to randomly choose a pin on which to run the WHOLE on/off cycle.
Here's my pseudocode. Or maybe it IS my code.
void setup() {
int pin = 0;
int fadeIn = 0;
int fadeOut = 0;
int onDuration = 0;
int offDuration = 0;
}
void loop() {
pin = random(2,8)
onDuration = random(2000,15000)
for (fadeIn=0;fadeIn<255;i++) {
analogWrite(pin,fadeIn)
}
delay(onDuration)
pin = random(2,8)
offDuration = random(1000,7000)
for (fadeOut=254;fadeOut>0;fadeOut--) {
analogWrite(pin,fadeOut)
}
delay(offDuration)
}
The loop (on, then off) would be one instance of a cycle. If I wanted a SECOND instance of the cycle to kick off on another pin WHILE the first cycle was running, is that something I can do programmatically? or would I need eight controllers, each fading the light in and out at the same time?