November 23, 2024, 10:33:57 PM

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.


Using the Prop-1, an AP-8, and a DC-16 to direct segments to a single speaker

Started by Spooky Dad, August 24, 2008, 07:55:43 PM

Previous topic - Next topic

JonnyMac

Exactly.  From the beginning I was thinking that you were going to use relays.  Honestly, I became very concerned when you suggested you wanted to make direct connections.
Jon McPhalen
EFX-TEK Hollywood Office

Spooky Dad

Attached is the code that I perfected last season for a fully automated haunted house.  Enjoy and don't hesitate to ask questions.  Remember that the brains of the haunt consist of a Prop-1, an AP-8, a DC-16 and a RC-4.

' =========================================================================
'
'   File...... Spooky_Dad_Halloween_2010.BS1
'   Purpose... Automate the House on Two Jacks Trail
'   Author.... Karlen Alexander
'   E-mail.... karlen_alexander@dell.com
'   Started... 8/23/2008
'   Updated... 10/31/2010
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
'SYMBOL UNUSED          = 6
SYMBOL  Ghost           = 5                     ' ULN as pull-dn
SYMBOL  Graveyard       = 4
SYMBOL  CPT             = 3
SYMBOL  Snakes          = 2
SYMBOL  MIB             = 1
SYMBOL  Entrance        = 0


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

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

SYMBOL  MIBRun          = 2500                 ' box is 10s
SYMBOL  MinJump         =  500                 ' timing for lid/box jumps
SYMBOL  MaxJump         =  750

SYMBOL  Baud            = OT2400


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

SYMBOL  idx             = B0                    ' selected sensor
SYMBOL  sensors         = B1                    ' sensor bits
SYMBOL  timer           = B2                    ' debounce timer
SYMBOL  mask            = B3                    ' inputs mask
SYMBOL  pntr            = B4                    ' EEPROM data pointer
SYMBOL  relays          = B5                    ' RC-4 bits
SYMBOL  track           = B8                    ' AP-8 track
'SYMBOL  cmd             = B7                    ' AP-8 command

SYMBOL  outBits         = W4
SYMBOL   outBitsL        = B8                   ' DC-16 bits
SYMBOL   outBitsH        = B9

SYMBOL  lottery         = W5                    ' random value
SYMBOL  mibtoggle       = B12                   ' used to alternate the MIB cylinders
SYMBOL  delay           = B13                   ' random delay for MIB
SYMBOL  mibtimer        = W3                    ' timer to keep track of how long MIB is running

' -----[ Initialization ]--------------------------------------------------
  PAUSE 60000                                   ' Give motions a chance to settle

Reset:
  DIRS = %00000000                              ' all inputs

  idx = Entrance
  mask = %00000001                              ' mask for idx = 0
  GOSUB Kill_AP8

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

Main:
  outBits = 0
  relays = 0
  GOSUB Set_DC16
  GOSUB Set_RC4
  sensors = %00111111                           ' assume active
  FOR timer = 1 TO 20                           ' debounce inputs
    RANDOM lottery                              ' stir random value
    PAUSE 5
    sensors = sensors & PINS                    ' scan inputs
  NEXT
  sensors = sensors & mask                      ' isolate current sensor
  IF sensors = %00000000 THEN Main              ' try again if not active
  pntr = 3 * idx                                ' point to data for idx

Set_Outputs:
  READ pntr, outBitsH
  GOSUB Set_DC16
  pntr = pntr + 1
  READ pntr, relays
  GOSUB Set_RC4

Start_Audio:
  IF idx = CPT THEN Audio_Delay
  pntr = pntr + 1
  READ pntr, track
  GOSUB Play_AP8

MIB_Check:
  IF idx <> MIB THEN Audio_Delay
  mibtimer = 0                                      ' reset timer for MIB
'  DEBUG mibtimer
  PAUSE 3000

MIB_Again:
    RANDOM lottery                                ' re-stir
    delay = MaxJump - MinJump + 1                 ' get span
    delay = lottery // delay + MinJump            ' calc jump timing
    mibtoggle = IsOn - mibtoggle                  ' toggle cylinders
    PAUSE delay
    mibtimer = mibtimer + delay                         ' update run timer
    IF mibtoggle = 0 THEN MIB_IsOn
    outBitsH = %00000010
    GOTO Skip_MIB_IsOn

MIB_IsOn:
    outBitsH = %00000001                          'need to verify bits to go high

Skip_MIB_IsOn:
    GOSUB Set_DC16
    DEBUG idx, mibtoggle, delay, mibtimer, %outBitsH
    IF mibtimer < MIBRun THEN MIB_Again              ' if not done, go again
    outBitsH = %00000000
    GOSUB Set_DC16
    GOSUB Kill_AP8
    GOTO MIB_Skip

Audio_Delay:
  DEBUG CR, CR, "Next Prop", CR, idx, track, %OutBitsH, %relays
  PAUSE 7500

  IF idx = Ghost THEN Reset

MIB_Skip:
    idx = idx + 1                                 ' next sensor #
    mask = mask * 2                               ' update sensor mask
    GOTO Main

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

Kill_AP8:
  SEROUT Sio, Baud, ("!!!!!AP8", %00, "X")
  RETURN
' -------------------------------------------------------------------------

'Loop_AP8:
'  cmd = "L"
'  GOTO Cmd_AP8

Play_AP8:
'  cmd = "P"

'Cmd_AP8:
  SEROUT Sio, Baud, ("!AP8", %00, "P", track, 2)      ' replaced cmd with P to save variable space
  RETURN

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

Set_DC16:
  SEROUT Sio, Baud, ("!DC16", %00, "S", 0, outBitsH)
  RETURN

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

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

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

'          DC-16 H    RC-4  AP-8
Show_Data:
  EEPROM (%00000000, %0000, 0)       ' idx = 0  Entrance
  EEPROM (%00000001, %0001, 1)       ' idx = 1  MIB - 24 volt solenoid
  EEPROM (%00000100, %0010, 2)       ' idx = 2  Snakes - 12 volt solenoid
  EEPROM (%00001000, %0100, 0)       ' idx = 3  CPT - 24 volt solenoid
  EEPROM (%00010000, %1000, 4)       ' idx = 4  Graveyard - 12 volts for LED
  EEPROM (%00100000, %0000, 7)       ' idx = 5  Ghost - 12 volts for LED

livinlowe

I have been thinking on how to send sounds to different, selectable speakers for a while. Haven't found anything yet. Please let us know if using the DC-16 works.
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

I wrote a program (should be here in the forums) for a customer where a DC-16 was used to select a set of speakers before the play command was sent to the AP-8.  It was pretty easy.  Just make sure that the relay work is handled when the AP-8 is not playing.
Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

Relays....I hate it when I prove to myself I'm dumb. I was thinking some kind of chip, relays or even a RC-4 would allow you to select which speaker comes on. Ha Ha! Yeah, I knew that  :-\
Shawn
Scaring someone with a prop you built -- priceless!

JackMan

Another neat little trick is to use the left/right channels of an AP-16+. Just create your sound files on either left or right channel and that particular file will only play on that speaker. Of course this will only give you two different speaker locations but it's easy to do without adding any hardware.

bsnut

Quote from: JonnyMac on May 05, 2011, 10:45:29 AM
I wrote a program (should be here in the forums) for a customer where a DC-16 was used to select a set of speakers before the play command was sent to the AP-8.  It was pretty easy.  Just make sure that the relay work is handled when the AP-8 is not playing.
Is this the program you are talking about Jon? I had it saved on my hard drive.

' =========================================================================
'   File......4x_AP8_Sound_Controller.BS1
'   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... 24 AUG 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN

SYMBOL  PIR4            = PIN3                  ' uses ULN as pull-down
SYMBOL  PIR3            = PIN2
SYMBOL  PIR2            = PIN1
SYMBOL  PIR1            = PIN0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  status          = B0
SYMBOL   playing        =  BIT7

SYMBOL  sensors         = B2
SYMBOL  idx             = B3
SYMBOL  mask            = B4
SYMBOL  ctrlBits        = B5

SYMBOL  delay           = W4
SYMBOL  lottery         = W5


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

Reset:
  SEROUT Sio, Baud, ("!!!!!!AP8", %00, "X")     ' resync and kill sound
  SEROUT Sio, Baud, ("!DC16", %00, "X")


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

Main:
  sensors = %00001111                           ' assume active
  FOR idx = 1 TO 10
    sensors = sensors & PINS                    ' scan PIRs
    PAUSE 10
    RANDOM lottery
  NEXT
  IF sensors = %00000000 THEN Main

Find_Sensor:
  RANDOM lottery                                ' re-stir
  idx = lottery // 4                            ' random, 0 to 3
  LOOKUP idx, (%0001, %0010, %0100, %1000), mask
  mask = sensors & mask                         ' isolate one sensor
  IF mask = %0000 THEN Find_Sensor              ' if not this one, try again

  RANDOM lottery                                ' re-stir
  delay = lottery // 2501 + 500                 ' random, 0.5 to 3 seconds
  PAUSE delay

Activate:
  LOOKUP idx, (%00000011, %00001100, %00110000, %11000000), ctrlBits
  SEROUT Sio, Baud, ("!DC16", %00, "L", ctrlBits)
  PAUSE 100

Start_Audio:
  SEROUT Sio, Baud, ("!AP8", %00, "P", 0)

Audio_Hold:
  PAUSE 100
  SEROUT Sio, Baud, ("!AP8", %00, "G")
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Audio_Hold

  PAUSE 10000                                   ' retrigger delay
  GOTO Main


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


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


' -----[ User Data ]-------------------------------------------------------
William Stefan
The Basic Stamp Nut

livinlowe

Quote from: JackMan on May 05, 2011, 05:37:09 PM
Another neat little trick is to use the left/right channels of an AP-16+. Just create your sound files on either left or right channel and that particular file will only play on that speaker. Of course this will only give you two different speaker locations but it's easy to do without adding any hardware.

Yeah, that would work slick as well. I went to an amusment park here in utah in October one year. In one of  their haunted houses they had a corrider you walked down. You would get a certain distance then you would hear a growl behind you. Of course, there is nothing there. Walk a little further and there is another growl, only much closer. Still nothing behind you (of course), but the effect was quite unnerveing. Hence my thinking about activating seperate speakers. Cool!  :D
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

Okay, gang, posts in this thread has gone off topic -- let's get back to the original point.
Jon McPhalen
EFX-TEK Hollywood Office