LED Fireworks. (Better video.)
Coded 'em up and set 'em off on The Fourth of July. Video is only six seconds long, but we kept them going much of the evening next to the grill.
Software is a fixed-point physics simulation, and of course FastSPI_LED2.
Hardware is an @Adafruit_Industries “Neopixel” (WS2811) shield and an Arduino Uno.
It is even more eyewatering in real life than in the video-- the brightness of these LEDs made for a great ‘fireworks’ display.
You can’t just “fixed point physics simulation” and expect us not to be interested in the gritty details! 
Well, first of all: there is an underlying ‘physics simulation’: shells are launched up with an initial velocity (mostly up, but a little horizontal, too), and then there’s air resistance, and gravity slowing them down. Each airburst creates a number of sparks, each of which also has an initial velocity vector, which is affected over time by gravity and drag. The sparks are the same color as the shell from which they burst; they start out much brighter than the shell, but burn out quickly.
Normally, you might do this sort of thing using floating point math, seeing as how C has it built in. But on the ATmega, there’s no floating point hardware, so floating point math can be agonizingly slow. That’s where fixed-point math comes in, and the FastSPI_LED2 library helps out here: it provides support for a bunch of fixed-point operations on 16-bit and 8-bit values. These fixed-point functions are many times faster than the built-in Arduino floating-point versions. There’s still a lot to be done here in the future, but the fixed-point math support in v2 of the library isn’t bad.
For the X and Y position of each shell (and spark), I used 16-bit “accum88” type variables – meaning 8 bits before the decimal, and 8-bits after. For the XVelocity and YVelocity vectors, I used “saccum78” variables – meaning signed (hence the initial “s”) seven bit numbers, with an additional eight bits after the decimal point.
The rendering of shells and sparks onto the LED array uses more fixed-point math (for anti-aliased rendering), and also uses some of the new-in-v2 pixel functions. For example, when I’m rendering the sparks onto the LED array, I don’t just say leds[i] = sparkcolor;. Instead I say leds[i] += sparkcolor;. Note the difference: addition. By adding the brightness of this spark on top of whatever might be there already, the display is much smoother and more realistic. The FastSPI_LED2 library code deals with adding each color channel (RGB), and making sure they don’t wrap around past 255; they saturate instead of wrapping.
Finally, the colors are chosen using from the HSV color space, with something like this: hsv2rgb_rainbow( CHSV( random8(), 255, 255), sparkcolor);
So basically, I guess that this animation is using a pretty good percentage of the FastSPI_LED2 library: support for the WS2811, fixed-point variables, saturating arithmetic, whole-pixel addition, and HSV colorspace support.
Maybe I should also make a 1-dimensional version as a demo for v2 of the library! (I also have some Perlin noise to look into, too, speaking of fixed-point math…)
Can u share the code?
I just added a 1D fireworks entry to my pile o’ FastLED demos at https://github.com/atuline/FastLED-Demos. Sorry, I don’t have a matrix yet.
Awesome! Thanks
