once you see what’s underneath you’ll see that it is not as
scary as it seems at first blush.
There are two loops: the first sets up initial values; the
second runs the active flicker algorithm. Most of the
variables used by the flicker() method are local, but you’ll
see that it uses the external level array and the leds object
to control the wicks without further intervention by us.
The code also accesses the (global) flickerdelay variable
which affects the speed of wick movement.
At the top, a local random variable (lotto) is initialized
and a loop runs which sets the base value of each wick to
zero — the target in the upper range — and then randomizes
the ramp control. The direction bits are cleared to zero
which indicates that each wick is initially ramping up.
Now for the fun. At the start of each loop iteration,
the value in lotto is re-randomized so that it’s always
changing. For each wick, we decrement the ramp value
and when that hits zero we increment or decrement the
base value so that it moves toward the target. Once the
target is reached, a new (random) target is generated.
Whenever a wick brightess is modified, the new level
is set in the leds object. Note the use of the global level
array which acts as an overall brightness control value. As
we modify the level array in the main cog, it is used by the
flame cog. I think this is really cool.
Overall loop speed is dictated by the number of
■ FIGURE 12.
Jack in action.
active wicks and the value in flickerdelay. As we saw in the
main code, we can change flickerdelay to alter the
apparent behavior of the wicks. You’ll see there is just a
bit of math before the waitcnt command — this is needed
to prevent waitcnt from hanging (delay of about 56
seconds) when we have a small value in flickerdelay.
This process could be duplicated in another micro but
I believe it would be a much bigger coding challenge.
Introducing Pololu’s new line of
Maestro USB Servo Controllers
hree control methods: USB, TTL serial, and internal scripting
Channels can be used for digital I/O or up to 12 analog inputs
Individual servo speed and acceleration control for each channel
Up to 8 KB of internal scripting memory (~3000 servo positions)
0.25 us servo pulse resolution with pulse rate up to 333 Hz
Pololu's 6-channel Micro Maestro and new 12-, 18-, and
24-channel Mini Maestros take serial servo controllers to
the next level by incorporating native USB control for
easy connection to a PC and programmability via a
simple scripting language for self-contained, host
controller-free applications. Whether you want the best
servo controller available or a versatile, general-purpose
I/O control board, these compact devices will deliver.
more information at www.pololu.com/maestro
October 2010 43