dhiltonp/hexbright

Hard blink functionality? (Emulating a flakey / bad flashlight)

Solarbotics opened this issue · 3 comments

I've got a project that requires a "flakey flashlight", and remembered my nifty programmable Hexbright.

I thought I was clever trying to use this snippet to make it act like an intermittent connection:

hb.set_light(0, 500, NOW); //Turn on bulb
delay(random(100, 1000)); //leave it on for a bit
hb.set_light(CURRENT_LEVEL, 0, 40);  //let it die
delay(random(1000, 4000)); //leave it off a while

But now I see that the library really doesn't like working with inline delays. I've cribbed your bike strobe code to get me sort of close, but it doesn't let me have that "solid on" effect for a while before starting the decay.

I don't mind beating my head on the code wall to get the effect I'm after, but I sure could use a pointer to what methodology would do the job.

For what it's worth, I've added the successful code I have running so far.
Thx,
Dave
(rename to .ino as Github doesn't seem to like the .ino extension...)
hexbright_slenderman.txt

Ah. I just found other fancode at https://github.com/jangrewe/hexbright/blob/master/platypus/platypus.ino. I think I'll beat this up on my own YET....

I'd start with something like this:

int light_change_time = 0;
bool light_on = false;

void loop() {
  hb.update();
  if millis() > light_change_time {
    if light_on {
      hb.set_light(CURRENT_LEVEL, 0, 40);  //let it die
      light_on = false;
      // stay off for 0-2 seconds
      light_change_time = millis() + random(2000);
    } else {
      hb.set_light(0, 500, NOW); //Turn on bulb
      light_on = true;
      // stay on for up to 15 seconds
      light_change_time = millis() + random(15000);
    }
  }
}

Excellent. Thanks for the tip. I've rounded out the codebase for anybody else wanting to do the same. Sorry, bit of a github newb, so I'll just drop a copy here.
hexbright_slenderman_0.2.txt