I have a series of eight LEDs that I'm trying to fade in and out randomly, starting from ON. Here's where I am so far.
#define LED1 2
#define LED2 3
#define LED3 4
#define LED4 5
#define LED5 6
#define LED6 7
#define LED7 8
#define LED8 9
void setup() {
pinMode(LED1,output);
pinMode(LED2,output);
pinMode(LED3,output);
pinMode(LED4,output);
pinMode(LED5,output);
pinMode(LED6,output);
pinMode(LED7,output);
pinMode(LED8,output);
}
void cycleLED() {
timeOn = random(600,1800);
timeOff = random(600,1800);
for (fadeOut = 255; fadeOut > 0; fadeOut--) {
analogWrite(LED, fadeout);
delay(timeOff);
}
for (fadeIn = 0;fadeIn < 255; fadeIn++) {
analogWrite(LED,fadeIn);
delay(timeOn);
}
}
Here's where I'm stuck. I want to do something similar to the following pseudocode.
activeLED = random(2,10); // choose a random LED pin
LEDtoCycle = pinNumber-activeLED; // set the active LED to the random LED pin
cycleLED(pinNumber-activeLED); // run cycleLED on the active LED
My intention is to select an LED at random, then to run cycleLED on that LED, repeating indefinitely. By choosing random However, I'm having a hard time wrapping my head around a good way to do this. How do I pass the pin variable to cycleLED()? Or should I repeatedly #define a single, random LED? Or should I just hardcode eight separate instances of cycleLED1(), cycleLED2(), cycleLED3(), and so forth.
Tips or suggestions?