November 23, 2024, 06:12:40 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.


JonnyMac's Haunted Pumpkin

Started by JonnyMac, November 01, 2008, 12:43:24 PM

Previous topic - Next topic

JonnyMac

When not online here I spent most of the last week or so running around the San Fernando Valley helping as many friends as I could.  Late yesterday, just before jumping into the shower so I could go to a couple Hallween parties I finished a decoration I'd been promising the neighbors for two years.  He ladies next door always decorate our stairwell with spiders and little pumpkins so I bought one of those carvable foam pumpkins and haunted it.  I gave it a rat friend with glowing LED eyes.

Here's the setup on the neighbor's shoe stand:



The pumpkin has three candle-ized WickLEDS (see: http://www.efx-tek.com/php/smf/index.php?topic=879.0) to light it and the rat has two LED eyes.

I used a Prop-1, AP-8, and Parallax PIR to control everything.  I mounted the PIR in a cardboard tube to cut down its field-of-view.  Here's the control panel:



And, finally, the code.  I wanted just one candle to flicker while the prop is waiting for a PIR input and then all three to light up when audio is running.  The way I did this is to manipulate the DIRS register; this let me use my Hold_AP8 subroutine to flicker the [enabled] candles while waiting for audio to finish.  This is a trick worth using from time-to-time (you'll see it in a Menorah program I have ready for Hanukkah).

' =========================================================================
'
'   File...... JonnyMac_Pumpkin.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... 29 OCT 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' AP-8 Sounds
'  0 :: reverse scream
'  1 :: "get out..."
'  2 :: belch
'  3 :: "happy halloween"
'  4 :: evil laugh
'  6 :: wolf/lightning


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Eyes            = 3                     ' rat eyes
SYMBOL  Wick3           = PIN2
SYMBOL  Wick2           = PIN1
SYMBOL  Wick1           = PIN0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  status          = B0
SYMBOL   playing        =  BIT7

SYMBOL  timer           = B1

SYMBOL  idx             = B2
SYMBOL  idx2            = B3
SYMBOL  last            = B4
SYMBOL  mask            = B5
SYMBOL  check           = B6
SYMBOL  playList        = B7
SYMBOL  sfx             = B8
SYMBOL  wicks           = B9

SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000001                              ' just one wick at start

  SEROUT Sio, Baud, ("!!!!!AP8", %00, "X")      ' stop AP-8 if on
  PAUSE 20000                                   ' PIR warm-up/pgm delay


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' stir random #
  Wick1 = lottery                               ' flicker one wick
  PAUSE 25                                      ' loop pad
  timer = timer + 25 * Trigger                  ' update timer
  IF timer < 150 THEN Check_Trigger             ' wait for 0.15 sec input

Select_Show:
  RANDOM lottery                                ' stir random #
  idx = lottery // 3                            ' idx = 0 to 2 (random)
  IF idx = last THEN Select_Show                ' no repeats
    last = idx                                  ' save for next cycle
  LOOKUP idx, (%001, %010, %100), mask          ' convert to bit mask
  check = playList & mask                       ' played
  IF check <> %000 THEN Select_Show             ' if yes, try again
    playList = playList | mask                  ' not yet, so mark it
    IF playList <> %111 THEN Run_Show           ' list complete?
      playList = %000                           ' yes, reset it

Run_Show:
  BRANCH idx, (Show_0, Show_1, Show_2)

Show_0:
  GOSUB Eyes_On
  FOR idx2 = 0 TO 1
    LOOKUP idx2, (%00001111, %00001000), DIRS
    LOOKUP idx2, (1, 0), sfx
    GOSUB Play_AP8
    GOSUB Hold_AP8
    PINS = %00001000                            ' clear wicks
  NEXT
  GOSUB Eyes_Off
  GOTO Reset

Show_1:
  DIRS = %00000111                              ' allow wicks
  FOR idx2 = 0 TO 2                             ' play 3 segments
    LOOKUP idx2, (2, 4, 3), sfx                 ' set segment
    GOSUB Play_AP8                              ' play it
    GOSUB Hold_AP8                              ' let it finish
  NEXT
  GOTO Reset

Show_2:
  GOSUB Eyes_On
  DIRS = %00001111                              ' allow eyes & wicks
  sfx = 6
  GOSUB Play_AP8
  GOSUB Hold_AP8
  PINS = %0001000                               ' clear wicks
  GOSUB Eyes_Off
  GOTO Reset


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

Play_AP8:
  SEROUT Sio, Baud, ("!AP8", %00, "P", sfx)     ' play slot "sfx"
  RETURN

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

' Flicker wicks while waiting for AP-8 to finish
' -- control wicks by manipulating the DIRS register

Hold_AP8:
  FOR timer = 1 TO 3                            ' stir random #
    RANDOM lottery
  NEXT
  wicks = lottery & %00000111                   ' isolate 3 wicks
  PINS = PINS & %00111000                       ' clear old wicks
  PINS = PINS | wicks                           ' add new wicks
  SEROUT Sio, Baud, ("!AP8", %00, "G")          ' request status
  SERIN  Sio, Baud, status                      ' receive it
  IF playing = Yes THEN Hold_AP8                ' done yet?
    RETURN

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

Eyes_On:
  FOR timer = 0 TO 255                          ' fade eyes on
    PWM Eyes, timer, 1
  NEXT
  HIGH Eyes                                     ' keep eyes on
  RETURN

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

Eyes_Off:
  FOR timer = 255 TO 0 STEP -1                  ' fade eyes off
    PWM Eyes, timer, 1
  NEXT
  RETURN


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

Jon McPhalen
EFX-TEK Hollywood Office

HauntedWolf

Robert

Haunted Wolf Hollow - http://www.hauntedwolfhollow.com

JonnyMac

No, it' just flickers candles so I didn't think that shooting video would be worth doing -- silly me.
Jon McPhalen
EFX-TEK Hollywood Office