Go Down

Topic: Random Strobe Code help (Read 1 time) previous topic - next topic


Dec 30, 2011, 05:31 pm Last Edit: Dec 30, 2011, 07:07 pm by kl3vr Reason: 1

I recently realized an attiny13a was driving a flashlight driver board of mine.  This has inspired me to code a custom driver program.   So far I hope I'm on the right track with my program, but I need help with one feature:


at the 30s mark he engages random strobe.   Isn't it brutal?  How do I code this madness?  If someone could generalize it for me that'd be awesome.

Thanks for your time,


It's just like the Blink or Blink Without Delay examples but using the function random() to pick on and off times.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


just add the following line at a strategic place:

interval = random(min, max);  // fill in appropiate values for min and max   Note they are milliseconds.

In an elaborated version you could use different timing or fixed for the OFF and for the ON phase of the LEDs or take care that ON + OFF is a fixed time
(fixed frequency, random duty cycle)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


ok i'm am only a beginner but try this
it should set how long the light will be on and off
Code: [Select]
void loop() {
  ontime = random(20, 50);
  offtime = random(20, 50);
  digitalWrite(13, HIGH);
  digitalWrite(13, LOW);


Thanks for the responses.  I had tried a delay(random(min,max)) before but didn't like the effect, probably the 5mm led was too weak to imitate a flashlight's strobe.  Anyways thanks again!

Go Up