here's why: In a strip project like Matt's, I want to have
each LED be its own color; in a ring project like mine, this
doesn't work as well. So, what I want to do is create
groups of LEDs (super pixels) to produce a stronger
effect:
If you've already used a Propeller Mini, you know that
FIGURE 5.
pub randomize_flames(size) | idx, used, ch,
last
idx := 0
repeat
used := %00000000
repeat while (used <> %11111111)
ch := prng.random & %111
if (ch <> last)
ifnot ((1 << ch) & used)
repeat size
Scramble[idx++] := ch
if (idx == N_PIXELS)
return
This code is simple, if not obvious. What we're
doing is looping through the Scramble array,
assigning a random index to the number of
elements defined by size. The index can be 0 to 7
to correspond with the heat array we created earlier. Two
variables are employed to ensure a proper mixing of the
indexes: used makes sure that all indexes are, in fact,
assigned before there are any repeats, and last ensures
that the same index is not assigned to side-by-side
channels.
Here's the fun part: With all of that prep, the mainline
code requires just a few lines:
pub main | ch, color
setup
randomize_flames(6)
repeat
repeat ch from 0 to N_PIXELS-1
color := morph(COOL, HOT, heat[Scramble[ch]])
strip.set(ch, color)
This happens to be from my pumpkin project; I used
six in randomize_flames() to convert my 24-pixel ring into
four groups of LEDs (“super pixels” of the same color).
Why? Well, for a ring project, having too many small
colors causes them all to blend together, resulting in a
“mushy” average that lacks any of the characteristics we
associate with flames. By using fewer elements, we restore
the sense of brightness changes and motion that suggest
real candles in a Jack-o-lantern.
You've seen Matt's cool project; here's mine: I decided
to upgrade my faux Jack-o-lantern from a couple years ago
with a ring of WS2812 LEDs. There's nearly nothing to it: I
used a Propeller Mini, a ring of WS2812s, a DC-DC power
supply, and a 2.1 mm pigtail so that everything can be
very modular.
30 September 2015