Pages: [1]   Go Down
Author Topic: Random Strobe Code help  (Read 782 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: December 30, 2011, 01:07:37 pm by kl3vr » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8662
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's just like the Blink or Blink Without Delay examples but using the function random() to pick on and off times.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13477
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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)
Logged

Rob Tillaart

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

Down Under (Australia), SA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 83
Newbie is an understatement
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Pages: [1]   Go Up
Jump to: