DIY Arduino project inspired by Fran Blance's "Fireflies in a Jar".
http://www.frantone.com/Digital_Fireflies/frans_digital_fireflies.html
A mumbly-fumbly fuddy-duddy explains how he made a novel gift with little "fireflies" (little lime-green surface-mount LEDs on thin wires inside a glass vase).
This is my first foray into "giving back" to the open-source community but hopefully I'll find time to share more stuff later. I have uploaded schematic and sourcecode to Github.
https://github.com/frumperino/fireflies
I realize some of the code is terse and I use timer interrupts and custom data types and function pointers for structuring my code, but I honestly don't know any other way to achieve something like this. Don't be intimidated by things that are slightly out of your comfort zone, just dive into it and pick it apart and ask questions until you understand it. I knew almost nothing about C programming when I first got exposed to Arduino some 5 years ago. Since then I have made a career out of developing electronics and that often involves microcontroller programming. I still use Arduino quite often for prototyping.
I have refactored, modularized and documented the code so that it is hopefully easier for anybody interested to take apart, use and adapt for their own projects.
The Arduino code contains two almost-libraries in the form of "clump-in" code snippets for driving the PWM LED matrix and also a separate function used here for animating the fireflies but which could also be used for sound or servo sequencing.
The fireflies software itself
The code works by using a couple of parallel processes together:
On a 250KHz Timer1 interrupt I have the LED driver which produces 7-bit (128-level) PWM (analog out) voltages for each of the 12 LEDs. That's the "display" of the fireflies. It runs all the time and eats probably about half of the available CPU cycles.
To generate "content" for the display I am running several independent "Animators" in parallel, one for each "firefly" that can be shown together. I have selected 3 for this example, but you can adjust the number in your code!
Each Animator is randomly assigned to one of the 12 LEDs, and it is responsible for iterating through a "sequence" that defines the brightness over time through a slow firefly "blink", which consists of a rise in brightness followed by a peak held for a short while and then a slow fade-out.
As each of the animators complete their sequence (of a "blink"), the corresponding firefly "dies" and is "reborn" in a different LED, with new randomized animation parameters to vary the next blink sequence.
In the video I also describe how I drilled a hole in the bottle for feeding a USB cable through for external control, but I forgot to mention that if you cut a USB cable you should be careful to keep the data wires twisted after you splice them back up: The twisted wires helps shield the balanced differential signal from noise.
Questions and follow-ups welcome.
Shout-outs to DZL, Frantone and Dave's excellent EEVblog