November 24, 2024, 02:05:32 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Code for props. Is it ok

Started by FAMOUS5, October 28, 2014, 10:28:53 AM

Previous topic - Next topic

FAMOUS5

All I am trying to do is use a PIR sensor to trigger a output for a solenoid and change audio from ambient to a specific file "PW". Is the volume control going to work in the reset routine?  Thanks

bsnut

Welcome first off.

Can post your code by copying and pasting it so we can see what you have without needing to open Stamp Editor. This makes it easier for everybody to see the code and help you.

You do this by using the drop down menu at the top of the posting box selecting

Font face > Font size > Color change

By doing this everyone can see your code.
William Stefan
The Basic Stamp Nut

FAMOUS5


' =========================================================================
'
'   File...... Prop Code.bs1
'   Purpose... Movement, ambient, specific prop attack sound
'   Author.... George Dodds ( with assist from JonnyMac! )
'   E-mail.... george.doddsjr@fivesgroup.com
'   Started...
'   Updated... 28 OCT 2014
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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

'   This code will play ambient track and when PIR is triggered the attack
'   sound will play and cyclinder extend solenoid will turn on.


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


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

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


SYMBOL  cyc_ext        = PIN0                  ' use OUT0/Turns V- ON for Cylinder
                                               ' extend solenoid.

' -----[ 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 = %00000000                             ' all outputs off
  DIRS = %00111111                             ' P5..P0 are outputs

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

  PAUSE 10000                                  ' PIR warm-up/delay ***CHANGED FROM 20000***


' -----[ 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


  cyc_ext = IsOn

  SEROUT Sio, Baud, ("!AP16", %00, "PW", "file", 13, 1)
   ' ***Play sound effect, CHANGE ***"file"*** to prop track***
Audio_Wait:
  PAUSE 100
  SEROUT Sio, Baud, ("!AP16", %00, "G")
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Audio_Wait

  GOTO Reset





JonnyMac

Here's a slight modification that gives you some flexibilty, and allows you to test files on the AP-16+ using manual input.

' =========================================================================
'
'   File...... Prop Code.bs1
'   Purpose... Movement, ambient, specific prop attack sound
'   Author.... George Dodds ( with assist from JonnyMac! )
'   E-mail.... george.doddsjr@fivesgroup.com
'   Started...
'   Updated... 28 OCT 2014
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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

'   This code will play ambient track and when PIR is triggered the attack
'   sound will play and cyclinder extend solenoid will turn on.


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


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

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

SYMBOL  Cylinder       = PIN0                  ' use OUT0 and V+

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

SYMBOL  Yes            = 1
SYMBOL  No             = 0

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

SYMBOL  Extend         = 1
SYMBOL  Retract        = 0

SYMBOL  Baud           = OT2400


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

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

SYMBOL  timer          = B2                    ' for debounce loop

SYMBOL  volume         = B3                    ' for AP-16+
SYMBOL  sfx            = B4
SYMBOL  repeats        = B5


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

Power_Up:
  PAUSE 3000                                   ' let AP-16+ initialize

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

  volume = 50                                  ' half volume
  GOSUB Set_Volume

  sfx = 0                                      ' play SFX00.WAV forever
  repeats = 0
  GOSUB Play_SFX

  PAUSE 10000                                  ' 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

  Cylinder = Extend

  volume = 100                                 ' full volume
  GOSUB Set_Volume
  PAUSE 25

  sfx = 1                                      ' play SFX01.WAV once
  repeats = 1
  GOSUB Play_SFX

Audio_Wait:                                    ' wait for audio to finish
  PAUSE 100
  SEROUT Sio, Baud, ("!AP16", %00, "G")
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Audio_Wait

  GOTO Reset


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

Set_Volume:
  SEROUT SIO, Baud, ("!AP16", %00, "L", volume, volume)
  RETURN

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

Play_SFX:
  SEROUT SIO, Baud, ("!AP16", %00, "PS", sfx, repeats)
  RETURN
Jon McPhalen
EFX-TEK Hollywood Office

FAMOUS5

Great thanks. FYI we came up with a spare Prop-1 and PIR switch. I was able to talk to the board and the PIR and prop-1 output seem to be ok but I don't have the AP-16 to complete the program and turn off the output. I am working on trying to make the trigger faster, what would be the correct way to modify the current code.

THANKS AGAIN

George

livinlowe

PIR sensors and faster reaction times in the program often lead to frustration. With PIR sensors being as 'twitchy' as they are naturally, I think you would be better off with waiting a while to make sure you are getting a correct trigger (i.e. its a person not just the sensor randomly reacting).

Just my 2 cents!

Shawn
Shawn
Scaring someone with a prop you built -- priceless!

FAMOUS5

Ok if you think this is good for a person walking by to trigger our prop I will take your word and let it be. We re using ABS (black) to try to focus a more narrow beam. Does it matter if it black ABS or White PVC let me know.
once again THANKS
George

JackMan

You can narrow the PIR's field of view with any material, color doesn't matter. As for making the trigger faster, not sure what you mean by that, the program is set for a tenth of second which is pretty much instantaneous.  ;)

JonnyMac

Some people say that if you take the Fresnel lens off the PIR you get more directional response. By design, PIRs have a wide angle of view -- a great deal of this comes from the use of the lens.
Jon McPhalen
EFX-TEK Hollywood Office

bsnut

Never though of that. Taking the lens off sounds like a good idea to try. Of course I will report my findings here.
William Stefan
The Basic Stamp Nut