November 24, 2024, 12:16:26 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


programing an ambient plus...

Started by aquawilly54, October 14, 2014, 09:06:34 PM

Previous topic - Next topic

aquawilly54

Hi folks.
  It's been a couple of years since I tried using the Prop 1 and AP-16+.  I needed help then for Halloween, and I'm going to ask for help again.  I tried my best to write a program for the prop 1 incorporating the AP16+. Admittedly some parts are copied from past programs that worked.   I don't feel to awful bad about it, but I haven't tried it out yet simply because I'm sure I have made some errors.  I think I have most of it down, but the ambient wav has me a bit befuddled.  I'm pasting the program sheet in here, and hoping you experts can spot any issues with it and help me out.  I've included a program description on the sheet, so hopefully it makes sense to anyone looking at it.  I think it's fairly clear as to what I'm intending.   When I got help here those years ago (thank you again for that) somebody told me that "specific is the root of specificity."  That kinda stuck with me, so the description is about as specific as I can make it. 

My daughter is coming home for Halloween to play with her old man, so having this set up would really be a cool thing to wow her with.  I appreciate all inputs that my come.
Thank you in advance.
Steve
<aquawilly54@yahoo.com>


       ' =========================================================================
'
'   File......     Graveyard man
'   Purpose...     Movement, lights and random sounds
'   Author....     Steve
'   E-mail....     aquawilly54@yahoo.com
'   Started...     Oct, 2014
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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

-  Need Ambient.WAV playing, AND motor running.  Motor = pin 0
-  When PIR is triggered need the motor (pin 0) TO turn off, AND lights (Pin 1), Air cylinder solenoid (Pin 2), AND a RANDOM SFX##.WAV TO come on all at the same time.
-  After 10 seconds motor turns on, lights go off, air cylinder retracts, AND ambient wav starts again.
-  PIR waits 20 seconds FOR NEXT trigger


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


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

SYMBOL  Sio               = 7                       ' SETUP = UP; no ULN  (AP-16+)
SYMBOL  Trigger         = PIN6                  ' SETUP = DN  (PIR)

SYMBOL  Air cylinder    = PIN2                  ' use OUT2/V+
SYMBOL  Lights           = PIN1                  ' use OUT1/V+
SYMBOL  Motor           = PIN0                  ' use OUT0/V+


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  timer           = B2                    ' for debounce loop


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

Power_Up:
  PAUSE 3000                                    ' let AP-16+ initialize

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs

  PAUSE 20000                                   ' PIR warm-up/delay


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

Main:

HIGH Motor = IsOn                                  ' Motor runs constant with AMBIENT.WAV
SEROUT SIO, OT2400, ("!ap16", %00, "PW"  AMBIENT.WAV, 0)  ' Ambient.WAV active, Loop switch is closed, BR is off

B2  timer = 0                                      ' Reset debounce timer

IF Pir  = IsOff THEN Main                          ' wait for Pir activity

T00:
  LOW Motor = IsOff                                ' Motor turns off
  HIGH Lights = IsOn                               ' Lights on
  HIGH Air cylinder IsOn                           ' Air cylinder solenoid on
  SEROUT Sio, OT2400, ("!AP16", %01, "P?", 4, 1)   ' Play random SFX##.WAV one time (lights, air, and sound at same time)
  PAUSE 10000                                      ' All on for 10 seconds

T10:
  HIGH Motor = IsOn                                ' Motor runs constant with AMBIENT.WAV
  LOW Lights = IsOff                               ' Lights off
  LOW Air cylinder IsOff                           ' Air cylinder solenoid off
  PAUSE 20000                                      ' 20 seconds off before next activation

  GOTO Main                                        ' Wait for next activation

JonnyMac

Give this a try.

Note that this waits for the end of the randomized audio -- easier than making all the the files exactly 10s long.


' =========================================================================
'
'   File...... graveyard_man.bs1
'   Purpose... Movement, lights and random sounds
'   Author.... Steve ( with assist from JonnyMac! )
'   E-mail.... aquawilly54@yahoo.com
'   Started...
'   Updated... 14 OCT 2014
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio            = 7                     ' SETUP = UP; no ULN  (AP-16+)
SYMBOL  Trigger        = PIN6                  ' SETUP = DN  (PIR)

SYMBOL  Cylinder       = PIN2                  ' use OUT2/V+
SYMBOL  Lights         = PIN1                  ' use OUT1/V+
SYMBOL  Motor          = PIN0                  ' use OUT0/V+


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

SYMBOL  Yes            = 1
SYMBOL  No             = 0

SYMBOL  TrOn           = 1                     ' active-high trigger
SYMBOL  TrOff          = 0

SYMBOL  IsOn           = 1                     ' active-high I/O
SYMBOL  IsOff          = 0

SYMBOL  Baud           = OT2400


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

SYMBOL  status         = B0                    ' AP-16+ status byte
SYMBOL   playing       =  BIT7                 ' 1 when playing

SYMBOL  timer          = B2                    ' for debounce loop


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

Power_Up:
  PAUSE 3000                                   ' let AP-16+ initialize

Reset:
  PINS = %00000001                             ' motor on, others off
  DIRS = %00111111                             ' P5..P0 are outputs

  SEROUT SIO, Baud, ("!AP16", %00, "PW", "AMBIENT", 13, 0)

  PAUSE 20000                                  ' PIR warm-up/delay


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  Motor = IsOff
  Lights = IsOn
  Cylinder = IsOn

  SEROUT Sio, Baud, ("!AP16", %00, "P?", 4, 1) ' randomize SFX00..SFX04

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

  GOTO Reset
Jon McPhalen
EFX-TEK Hollywood Office

aquawilly54

Johnny Mac,
  Thanks for the help.  I really appreciate it.  Everything is working except for the Ambient.  I've gone over the docs until my eyes can't focus anymore.  I just can't find what the problem would be.  That said; the ambient is titled on the SD card just as the example shows
AMBIENT.WAV, so considering the SFXnn's work I'm a bit baffled once again. I even tried the A0 and A1 switches as a last ditch effort.  I figure I missed something, but I'm pasting the program here again just for gee whiz. 
Once again, thank you. 
Steve


' =========================================================================
'
'   File...... Johnny Mac Assist.bs1
'   Purpose... Movement, lights and random sounds
'   Author.... Steve ( with assist from JonnyMac! )
'   E-mail.... aquawilly54@yahoo.com
'   Started...
'   Updated... 14 OCT 2014
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio            = 7                     ' SETUP = UP; no ULN  (AP-16+)
SYMBOL  Trigger        = PIN6                  ' SETUP = DN  (PIR)

SYMBOL  Cylinder       = PIN2                  ' use OUT2/V+
SYMBOL  Lights         = PIN1                  ' use OUT1/V+
SYMBOL  Motor          = PIN0                  ' use OUT0/V+


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

SYMBOL  Yes            = 1
SYMBOL  No             = 0

SYMBOL  TrOn           = 1                     ' active-high trigger
SYMBOL  TrOff          = 0

SYMBOL  IsOn           = 1                     ' active-high I/O
SYMBOL  IsOff          = 0

SYMBOL  Baud           = OT2400


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

SYMBOL  status         = B0                    ' AP-16+ status byte
SYMBOL   playing       =  BIT7                 ' 1 when playing

SYMBOL  timer          = B2                    ' for debounce loop


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

Power_Up:
  PAUSE 3000                                   ' let AP-16+ initialize

Reset:
  PINS = %00000001                             ' motor on, others off
  DIRS = %00111111                             ' P5..P0 are outputs

  SEROUT SIO, Baud, ("!AP16", %00, "PW", "AMBIENT", 13, 0)

  PAUSE 20000                                  ' PIR warm-up/delay


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  Motor = IsOff
  Lights = IsOn
  Cylinder = IsOn

  SEROUT Sio, Baud, ("!AP16", %00, "P?", 4, 1) ' randomize SFX00..SFX04

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

  GOTO Reset



JackMan

A1 and A0 should be off, the last switch (#6 which is the ambient loop) should be on.

aquawilly54

Yup.  Like I said (in my frustration) it was a last ditch effort.   :) 

I was actually hoping to beat any replies, because I found the error.  Yep, it was me.  I recalled that I exported the recording under one name, then renamed it as AMBIENT.  Can't do that - as I finally remembered from my past dealings, so I went in re-recorded it, and exported it under the ambient.wav name, and it works just fine. 

Thank you Jack Man for the reply.  I like this forum, you guys are fast.   ;D  And once again; thank you Johnny Mac for getting me over the hump.  I will have more questions later on terminology/programing jargon, but for now I'm good.
Take care guys.
Steve

JackMan

Glad to hear everything is working although I'm not sure that the "re-naming" procedure was the culprit. You should be able to rename any .WAV audio file after the fact, I do it all the time.

JonnyMac

Some OSes are finicky about naming. What happens more often than not, is a person uses the name plus extention (e.g., AMBIENT.WAV) and the application adds another copy of the extension, so you get AMBITENT.WAV.WAV. For this reason I tell my computer to display extensions of files.

On my Windows 8.1 system I did this:
-- Open the Control Panel
-- Select Appearance and Personalization
-- Select Folder Options
-- Open View tab
-- Uncheck Hide extensions for known file types
-- Click OK to close dialog
Jon McPhalen
EFX-TEK Hollywood Office