I've been using this sketch to make 6-8 leds to blink a preset division of 1000ms:
/* Blink Multiple LEDs without Delay
*
* Turns on and off several light emitting diode(LED) connected to a digital
* pin, without using the delay() function. This means that other code
* can run at the same time without being interrupted by the LED code.
*/
const int NUMLEDS = 18;
byte pin[NUMLEDS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
byte state[NUMLEDS] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
unsigned long interval[NUMLEDS] = {66, 333, 666, 16, 4666, 233, 16, 33, 1111, 466, 399, 266};
unsigned long time[NUMLEDS];
void setup()
{
for (int i=0; i<NUMLEDS; ++i)
pinMode(pin
, OUTPUT);
}
void loop()
{
unsigned long m = millis();
for (int i=0; i<NUMLEDS; ++i)
if (m - time > interval)
{
time = m;
state = state == LOW ? HIGH : LOW;
digitalWrite(pin, state);
}
}
I would like to make the leds blink randomly and the only sketch I've found is the following & for only 1 led:
/*
* Blink_Randomly
*
* Modified from the basic Arduino example. Turns an LED on for a random time,
* then off for a (most likely) different random time. We use pin 13 because,
* depending on your Arduino board, it has either a built-in LED
* or a built-in resistor so that you need only an LED.
*/
int ledPin = 13; // LED connected to digital pin 13
long randOn = 0; // Initialize a variable for the ON time
long randOff = 0; // Initialize a variable for the OFF time
void setup() // run once, when the sketch starts
{
randomSeed (analogRead (0)); // randomize
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
randOn = random (100, 1200); // generate ON time between 0.1 and 1.2 seconds
randOff = random (200, 900); // generate OFF time between 0.2 and 0.9 seconds
digitalWrite(ledPin, HIGH); // sets the LED on
delay(randOn); // waits for a random time while ON
digitalWrite(ledPin, LOW); // sets the LED off
delay(randOff); // waits for a random time while OFF
}
Can someone get me started on writing a sketch for 2+ leds to blink random.
Thanks for your patience with a newbie. 