I really like the delay based lightning effect written by Daniel Wilson found here:
But, this is giving me issues in my code due to all the delay involved, as I’m using a push button. My push button doesn’t work to cycle through modes when the animation is waiting for the next lightning strike. Is there a better way to get this same effect without using delays so that my push button works at any time during the animation?
Here’s my code. The lightning effect is down on line 350. This is my first project using Arduino and coding in general, so I haven’t really been able to wrap my head around how to avoid using delay like this. The furthest I’ve gotten is to possibly use millis().
Normally you can use interrupt pins with a button, however with WS281x LEDs you can’t.
Would it be possible to check the button state like this?
EVERY_N_MILLISECONDS( 200 ) {buttonRead(); }
@Jason_Coon Thank you! This is great. I tweaked your code to have the lightning strike more randomly as in the original code. It seems that the original code still has more strokes that are slightly longer/brighter. Still trying to figure that out. But, this is great because I am able to move past the animation at any time with the push button. Here’s your code updated with my mods:
I added FastLED.clear() at the beginning to clear any colors that were loaded from previous palettes. I also used ledstart and ledlen from the original code to make the strikes more random on the strip. I’ll continue to tinker with this and will report back if I find any other way to make the strokes closer to the original.
In case anyone’s curious, here’s some pics of the Camelbak. Also, a video of the modes, including Jason’s lightning code in action: