this is a starting point for the software , there are three parameters:
BETWEEN is max number of milliseconds between two flashes
DURATION is the max duration of one flash
TIMES is the max number of subflashes in a flash
These numbers are randomized to get random effects (you might want to seed the random function)
it is based upon the tutorial blink without delay to do the timing between flashes - but it uses delay for the flashes themselves -
it can be rewritten completely without delays but that is left as an exercise for the reader
You can extend this to multiple LEDS with their own "rythm"
give it a try (it uses the onboard LED for easy testing)
//
// FILE: lightning.pde
// AUTHOR: Rob Tillaart
// DATE: 2012-05-08
//
// PUPROSE: simulate lighning POC
//
//
#define BETWEEN 2579
#define DURATION 43
#define TIMES 7
#define LEDPIN 13
unsigned long lastTime = 0;
int waitTime = 0;
void setup()
{
Serial.begin(115200);
Serial.println("lightning 0.0");
pinMode(LEDPIN, OUTPUT);
}
void loop()
{
if (millis() - waitTime > lastTime) // time for a new flash
{
// adjust timing params
lastTime += waitTime;
waitTime = random(BETWEEN);
for (int i=0; i< random(TIMES); i++)
{
Serial.println(millis());
digitalWrite(LEDPIN, HIGH);
delay(20 + random(DURATION));
digitalWrite(LEDPIN, LOW);
delay(10);
}
}
// do other stuff here
}