Let’s Get Technical
by James Antonakos
Electronic Theories and Applications From A to Z
Let’s Get Technical
Making the Illusion Real
Listing 1
Figure 1. Hand-held electronic
toy that creates many different
optical patterns on five colored
LEDs as they spin around.
F
o
r
E
l
e
c
t
r
o
n
i
c
s
NUTS & VOLTS
E
v
e
r
y
t
h
i
n
g
‘ Blink five LEDs in different patterns
tick var
rot var
led var
num var
patt var
poff var
counts var
pon var
state var
byte
word
word
word
byte[5]
byte[5]
byte[5]
byte[5]
byte[5]
Start:
‘ Initialize off/on tick counts
for Led = 0 to 4
counts[led] = 0
random num
if (Num // 10) > 5 then
patt[Led] = 1
else
Patt[Led] = 0
endif
if patt[led] = 1 then
random num
poff[led] = num // 16 + 1
random num
pon[led] = num // 16 + 1
low led
else
high led
endif
Next Led
‘ Begin one second of rotation
for rot = 1 to 20
‘ Perform 128 ticks of activity
for tick = 1 to 128
‘ Examine / adjust state of each LED
for led = 0 to 4
if patt[led] = 1 then
counts[led] = counts[led] + 1
if state[led] = 0 then
if counts[led] = poff[led] then
high led
state[led] = 1
counts[led] = 0
endif
else
if counts[led] = pon[led] then
low led
state[led] = 0
counts[led] = 0
endif
endif
endif
next led
next tick
next rot
Goto Start ‘ Repeat forever
End
22
In my last article, I challenged myself to duplicate
the interesting patterns created by five small
LEDs mounted on a spinning disk (Figure 1). My
three-year-old daughter does not know that I have
taken her $10 toy apart to assist in my investigation,
so I may end up in a miniature doghouse (or possibly even Clifford’s) if I cannot get the original device,
or my creation, working.
I decided to use the PIC 16F628 microcontroller in my design. This was a challenge, since I
had never before worked with a PIC, written code for
the device, or tried to program one. After obtaining
an EPIC programming board from Jameco
Electronics, along with a batch of 16F628s, it took
me about 30 minutes to get an LED flashing on a
protoboard. Then I had to think about how to flash
five LEDs at different rates, with the rates changing
randomly.
First, I watched the original toy again, trying to
get a handle on several properties: how fast the disk
was spinning; how many times a single LED flashed
during a single rotation; and how often the patterns
changed. If I could have videotaped the toy and
watched the LEDs flash in slow motion, I could learn
what I needed to learn. But, instead, I simply made an
estimate of what I
thought was happening. These estimates
were as follows: the
disk looked like it
was spinning at the
rate of 20 revolutions
per second; it looked
like there were
around 16 small dots
in a quarter revolution when the LEDs
were flashing quickly; and the patterns
changed once each
second.
Based on these
estimates, I decided
to use a tick-based
timing system.
Something happens
SEPTEMBER 2005