Here is the Fritzing layout: (with 12v's worth of AA batteries and a single LED for the 12v light)
and the schematic:
After making it on a breadboard, I had a PCB printed to make the process more compact:
The code is Rob Tillaart's lightning code. Simple and effective.
//
// 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 0
unsigned long lastTime = 0;
int waitTime = 0;
void setup()
{
randomSeed(analogRead(2));
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++)
{
digitalWrite(LEDPIN, HIGH);
delay(20 + random(DURATION));
digitalWrite(LEDPIN, LOW);
delay(10);
}
}
// do other stuff here
}
No comments:
Post a Comment