Thanks very much for the fast help. That solved my problem. In all honestly, I'm having some difficulty in really following along with millis() (and C in general) and I think it's partly due to an overall lack of experience and i'm also finding that my brain may just not be wired for this kind of stuff. Working on it though.
I was able to extrapolate your answer out to randomly blink 5 LEDs. However, I'm not sure if the code I came up with is overkill (i.e. defining all the new variables for each LED if statement). Posting just to to see if anyone has input.
Thanks again. Great community here.
// Blink 1 LED at a random interval (1 second to 5 seconds) without using delay()
//Curcuit: LEDs connected to pin 10, 12, 13, 1 & 2, all with 330 ohm resistors to ground.
int led1Pin = 10;
int led2Pin = 12;
int led3Pin = 13;
int led4Pin = 1;
int led5Pin = 2;
int led1State = LOW;
int led2State = LOW;
int led3State = LOW;
int led4State = LOW;
int led5State = LOW;
long previousMillis1 = 0;
long previousMillis2 = 0;
long previousMillis3 = 0;
long previousMillis4 = 0;
long previousMillis5 = 0;
long randInterval1 = 0;
long randInterval2 = 0;
long randInterval3 = 0;
long randInterval4 = 0;
long randInterval5 = 0;
void setup() {
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
pinMode(led4Pin, OUTPUT);
pinMode(led5Pin, OUTPUT);
randomSeed (analogRead (0));
}
void loop()
{
unsigned long currentMillis = millis();
//LED 1/////////////////////////
if(currentMillis - previousMillis1 > randInterval1) {
randInterval1 = random (1000, 5000);
previousMillis1 = currentMillis;
if (led1State == LOW)
led1State = HIGH;
else
led1State = LOW;
digitalWrite(led1Pin, led1State);
}
//LED 2/////////////////////////
if(currentMillis - previousMillis2 > randInterval2) {
randInterval2 = random (1000, 5000);
previousMillis2 = currentMillis;
if (led2State == LOW)
led2State = HIGH;
else
led2State = LOW;
digitalWrite(led2Pin, led2State);
}
//LED 3/////////////////////////
if(currentMillis - previousMillis3 > randInterval3) {
randInterval3 = random (1000, 5000);
previousMillis3 = currentMillis;
if (led3State == LOW)
led3State = HIGH;
else
led3State = LOW;
digitalWrite(led3Pin, led3State);
}
//LED 4/////////////////////////
if(currentMillis - previousMillis4 > randInterval4) {
randInterval4 = random (1000, 5000);
previousMillis4 = currentMillis;
if (led4State == LOW)
led4State = HIGH;
else
led4State = LOW;
digitalWrite(led4Pin, led4State);
}
//LED 5/////////////////////////
if(currentMillis - previousMillis5 > randInterval5) {
randInterval5 = random (1000, 5000);
previousMillis5 = currentMillis;
if (led5State == LOW)
led5State = HIGH;
else
led5State = LOW;
digitalWrite(led5Pin, led5State);
}
}