November 22, 2024, 12:06:58 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Hanukkah Menorah Program

Started by JonnyMac, November 17, 2008, 05:05:40 PM

Previous topic - Next topic

JonnyMac

For those of you wondering what you're going to do with the WickLEDs you just bought at their new lower price, here's an idea that will be a treat for your Jewish friends: an electronic Hanukkah Menorah.  I wrote my original Menorah program a couple years ago for Nuts & Volts and received a lot of very nice e-mails from Jewish readers -- it was really a gratifying experience. 

This is an update to that program and is completely manual so you can control the candle lighting speed.  In the Menorah lighting ceremony the center (Shamash) candle is lit first and then it is used to light the others, one for each day of Hanukkah.  Instead of a match you'll use a potentiometer circuit that is compatible with the Prop-2's RCTIME function.



You could use a Prop-Pot for this but it's not really designed for live control.  What I suggest is that you get a 10K (linear) pot, a 0.1uF cap and one of our extender wires.  Solder the cap between the wiper and one side of the pot (you'll want to construct it so that turning the pot clockwise causes the resistance to increase).  Take one of our 14" extenders and cut off one end.  Solder the white wire to the wiper lead of the pot and the black wire to the other side of the cap.  The red wire is not used -- just cut it off. 

Since parts vary you'll need to test your pot/cap circuit to see what the maximum value is.  Start by changing the "0" in this line:

#DEFINE Testing = 0

... to "1" to enable the pot test.  When you run the program a Debug screen will display the pot value.  As you rotate the pot clockwise you should see the value increase to a number around 600; in my case the max value was 588.  Make note of this number and then change the "1" back to "0" in the Testing definition to disable that.

The program has 10 stages: all off, light Shamash, Shamash+1 ... Shamash+8.  What we want to do, then, is take the pot value and convert it to a number between 0 (all off) and 9 (Shamash + eight candles).  Here's the tricky bit of code that does it:

  stage = rawPot ** 1115 MAX 9

Okay, I know a few heads have exploded -- Scanner's-style -- but it's not that bad once you understand the process.

1) Take your max pot reading and divide by 10
    -- 588 / 10 = 58.8 (this is our pot divisor)

2) We want to divide the raw input by this number, but can't because it's fractional.  Oh yes we can -- we will multiply the raw value by the reciprocal of the divisor.  We divide 58.8 into 1 and get 0.017.  We can use this value with the ** operator by multiplying it by 65536 (0.017 * 65536 = 1115).  I wrote about using the ** operator in this thread: http://www.efx-tek.com/php/smf/index.php?topic=49.0

Review:
  -- take your max pot reading and divide by 10 (pot divisor)
  -- divide 1 by the pot divisor (reciprocal)
  -- multiply the reciprocal by 65536 to get the ** multiplier
  -- replace the 1115 in my program with your calculated ** multiplier

When you run the program the CCW position of the pot will have all LEDs off.  A you rotate CW the Shamash will come on, then the day 1 candle, then day 2, etc., through day 8.  The wicks are controlled by manipulating the DIRS registers -- remember a pin must be an output to control the WickLED.  The bottom of the loop simply stirs up lottery and writes that to all possible candle pins; those that are presently enabled with light up.

Have fun -- and Happy Hanukkah!


' =========================================================================
'
'   File...... Hanukkah_Menorah.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 17 NOV 2008
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ Conditional Compilation Directives ]------------------------------

#DEFINE Testing = 0                             ' 1 to enable


' -----[ I/O Definitions ]-------------------------------------------------

WickSelect      PIN     15                      ' SETUP = out; no ULN
Shamash         PIN     8                       ' use OUT8
Candles         VAR     OUTL                    ' use OUT0 - OUT7


' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Yes             CON     1
No              CON     0


' -----[ Variables ]-------------------------------------------------------

rawPot          VAR     Word                    ' input for RCTIME
lottery         VAR     Word                    ' random #

stage           VAR     Byte                    ' lighting stage
pntr            VAR     Byte
idx             VAR     Byte
delay           VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000           ' set outputs


' -----[ Program Code ]----------------------------------------------------

Main:
  HIGH WickSelect                               ' charge RC circuit
  PAUSE 1
  RCTIME WickSelect, 1, rawPot                  ' read pot setting

  #IF Testing = 1 #THEN                         ' just show pot when testing
    DEBUG HOME, DEC rawPot, CLREOL
    PAUSE 100
    GOTO Main
  #ENDIF

  stage = rawPot ** 1115 MAX 9                  ' 0 (off) to 9 (all "lit")
  pntr = stage * 2                              ' point into table
  READ pntr, Word DIRS                          ' enable wick outputs

  FOR idx = 1 TO 3
    RANDOM lottery                              ' stir random #
  NEXT
  OUTS = lottery & %0000000111111111            ' update (enabled) wicks

  RANDOM lottery
  delay = lottery // 21 + 10                    ' 10 to 30ms
  PAUSE delay
  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Candle_Mask:
'                    +------------ Shamash
'                    |+----------- Day 8
'                    ||      +---- Day 1
'                    ||      |
  DATA  Word %0000000000000000
  DATA  Word %0000000100000000
  DATA  Word %0000000100000001
  DATA  Word %0000000100000011
  DATA  Word %0000000100000111
  DATA  Word %0000000100001111
  DATA  Word %0000000100011111
  DATA  Word %0000000100111111
  DATA  Word %0000000101111111
  DATA  Word %0000000111111111


Jon McPhalen
EFX-TEK Hollywood Office