intervalometer.pde
/*
intervalometer.pde
Flashes an LED for random-length intervals at random intervals
The first 'on' interval is set by MINON and MAXON, the 'off' interval
by MINOFF and MAXOFF (in seconds.)
*/
#define LED 0
#define FLICKER 100 // 1/10 second.
#define FLASHES 5 // flashes per second.
#define MINON 10 // minimum flash duration
#define MAXON 60 // maximum flash duration
#define MINOFF 30 // minimum off duration
#define MAXOFF 240 // maximum off duration
long time; // used for counting milliseconds and flashes.
int j; // loop counter
void flash() {
digitalWrite(LED, HIGH);
delay(FLICKER);
digitalWrite(LED, LOW);
delay(FLICKER);
}
void setup() {
// initialize the digital pin as an output.
pinMode(LED, OUTPUT);
// use unconnected input as a random seed
randomSeed(analogRead(1));
// Indicate operation by flashing 5x.
delay(1000);
for (byte j=0;j<FLASHES;j++) flash();
}
void loop() {
time = random(MINOFF, MAXOFF); // random OFF delay, seconds
for (j=0;j<time;j++)
delay(1000);
// now flash for a random time
time = random(MINON*FLASHES, MAXON*FLASHES);// random on delay, flashes
for (j=0;j<time;j++)
flash();
}
Generated by GNU enscript 1.6.4.