Go Down

Topic: Random Strobe Code help (Read 901 times) previous topic - next topic

kl3vr

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

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:

http://www.youtube.com/watch?v=1weIT8CHmi0#t=0m30s

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,
kl3vr

johnwasser

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: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

robtillaart


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)

tigerbomb8

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);
  delay(ontime);
  digitalWrite(13, LOW);
  delay(offtime);
}

kl3vr

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