This was a fun little project I put together in a few
hours for a homemade-themed gift exchange this
Christmas. Β I had on-hand a βFull Color LEDβ from
Radio Shack (part 276-0028) which caught my eye
on my last visit there.
The LED has a common anode and three
cathodes, one for each of the three primary colors:
red, blue and green. Β By changing the duty cycle
(the fraction of time the pin is low) on each of the
three pins controlling the colors, I could create any
color.
The next step was the housing. Β I found a good
candidate in a prize I had won for judging a technical
paper competition at Georgia Tech years ago. Β It was
a sphere with a golf ball inside that you had to move
around until it balanced on a tee. Β The sphere was a
good size and the polystyrene base made for an easy
mounting of the components.
My first thought for controlling the colors was a simple algorithm
that I think is called βthe drunkβs walkβ β for each step, choose
randomly which direction the step will be (one color a little
brighter, another a little dimmer). Β The problem with this is that
youβre unlikely to get far; youβll likely keep drifting around
wherever you start. Β The chances of wandering all the way to a
vibrant color were small and I certainly didnβt want this thing just
showing different shades of off-white!
Instead I devised a configuration of 10 nodes: Β three of them
pure colors, seven of them intermediates. Β The globe would
start randomly on one of these nodes. Β Every three seconds an
adjacent node would be randomly chosen and the color would
slowly shift to that one over the course of 20 steps.
Here is a graphical representation of the ten nodes showing
(roughly) their colors. Β The numbers show proportions of red,
blue and green respectively.
The result is a random walk that gets to the more vibrant
colors reasonably often. Β To be really nit-picky, I donβt use all
of the colors that could be generated, only those along the
defined paths.
The circuit is quite simple β a battery, a 5V regulator, a PIC
16F688 microcontroller, and three 470-Ohm resistors from
the LED to the control pins. Β I later replaced the battery with a
plug consisting of a βwall wartβ transformer and a 9V clip.
For more detail: Color Globe using PIC16F688 Microcontroller