just as we did above. The day indicator is then
decremented to point to the next candle. When all are lit,
we can quit the repeat loop.
The last step is to wait for one more press — this time,
to extinguish the candles. While I found a lot of good
information regarding the lighting sequence of the
Menorah, I never came across anything having to do with
extinguishing the candles. This routine, then, will very
slowly dim all at the same time:
repeat
until (getbutton(TRIG, 250) == true)
repeat level from 255 to 0
repeat day from 8 to 0
if (wicks[day] > 0)
wicks[day] := level
pause(24)
Note that we require a longer button press to
extinguish the candles. This is by design to prevent an
accidental bump of the button from extinguishing them
too early. Note, too, that the loop timing for the fade-out
is longer to create a nice, slow fade-out.
So, there you have it: a Propeller powered electronic
Menorah. I think you'll find the code easy to modify and
the candle simulation is far nicer than the old RC circuit.
You can find the complete program in the downloads
package as jm_pp12_menorah.spin.
THE KWANZAA KINARA
Before we move on, there is another, multi-day
holiday celebration that uses a special candelabra:
Kwanzaa. Those that celebrate Kwanzaa light the Kinara
which has seven candles (one for each day). Since the
Kinara candles are lit in ascending order each day, the
code is a little simpler.
That said, I employed a little trick in this program to
show you how to re-map outputs when they are not in the
desired order. Let's say, for example, that we built a
beautiful electronic Kinara and wired it with the outputs
connected to each candle, moving left to right, in
ascending order, like this:
1 2 3 4 5 6 7
The problem is that the Kinara candles are lit in this order:
2 4 6 1 7 5 3
In the event we can't (or don't want to) rewire the
project, we can remap the outputs with a simple table in
Spin. Here's a little table I created to remap the (
zero-indexed) day to the physical channel output on the board:
dat
kinara byte 3, 0, 6, 1, 5, 2, 4
On the first day (0), we will light the center candle
(black) which is connected to P3. On the second day, we
SPIN ZONE
will light the outermost red candle which is connected to
P0. The map should now make sense.
Here's the core code for the Kinara:
repeat
repeat
until (getbutton(TRIG, 100) == true)
pause(250)
if (getbutton(TRIG, 150) == false)
if (day < 7)
idx := kinara[day]
repeat level from 0 to 255
wicks[idx] := level
pause(6)
++day
else
repeat level from 255 to 0
repeat day from 6 to 0
if (wicks[day] > 0)
wicks[day] := level
pause(24)
quit
At the top, we have a little trickery concerning the
button input. Since the Kinara candles are lit in ascending
order and always start with the central candle, the
program doesn't know what day it is — we tell it with each
new press. What we do, then, is scan the button, wait a
bit, then check again (note these periods are slightly
longer than before). The idea is that a short button press
will light the next candle and a long button press will
extinguish those that are lit.
You can see that we treat the dat table like a simple
array, reading the correct output for the day that we're
presently lighting. Easy, right? I think so — and, it’s
definitely easier than rewiring a project.
See jm_pp12_kinara.spin for the complete,
commented listing.
For those that are interested in building a fully
functional Menorah or Kinara, I again encourage you to
consult the October ‘ 10 issue as there are detailed
instructions on building candles from LEDs and items that
you can pick up at any hardware store.
PLAYING WITH PROTOCOLS
More and more of those home Christmas displays that
I enjoy so much are coming under computer control. I
think a good chunk of the credit goes to a nifty bit of
freeware called Vixen which was developed and
maintained by my friend, KC Oaks.
If you're new to this stuff and really want to dive into
the fray, I suggest that you check out
www.doityourselfchristmas.com. It's a very active set of
forums with many knowledgeable, highly enthusiastic
members.
One of the more popular protocols supported by
Vixens and a favorite with many DIY Christmas lighting
enthusiasts is called Renard, which was created by a
gentleman named Phil Short. Most of the code on the 'net
for the Renard protocol is PIC-based as that's what Phil
uses, though I have seen an implementation done in SX/B.
The Renard system is typically set up such that one
November 2010 17