May 11, 2024, 11:01:28 AM

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.


PIR - Vmusic & 3 Relays

Started by michilson, August 24, 2009, 01:14:32 PM

Previous topic - Next topic

michilson

Hi there john please check my code work i think this is pritty close.

Here's a idea of what im looking to have happen.

Before the Pir see's movement i want relay 1 on

Once the pir is triggered:
Relay 1 is off
relay 2 is on
Sound1.mp3 starts to play
then pauses for about 15 - 20 sec of sound clip
Relay 3 turns on and hold for 10 sec then turns off
the sound1.mp3 is stopped
Relay 2 is turned off
Pause for 10 sec (reset)
Relay 1 is turned back on for next group.

This is what i put together. I have Vmusic on Pin 0 & 1. PIR on Pin 7 and Relays on 3-5

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


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


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

SYMBOL PIR = PIN7
SYMBOL Light1 = PIN3 'OUT3
SYMBOL Light2 = PIN4 'OUT4
SYMBOL Fog = PIN5 ' OUT5


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

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


' -----[ Variables ]-------------------------------------------------------
FogOn = 10000
A_Hold= 20000

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

Reset:
DIRS = %00111000 ' make P4-P7 outputs
Light1 = ISON


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

Main:
IF PIR = ISON THEN R_PGM
GOTO MAIN


R_PGM:
Light1 ISOFF
PAUSE 200
Light2 ISON
SEROUT 0, T2400, ("VSV $00", 13) 'set volume full (in hex), 'insert carriage return
SEROUT 0, T2400, ("VPF sound1.mp3", 13) 'play sound1.mp3, insert carriage return
PAUSE A_HOLD
Fog ISON
PAUSE FOGON
FOG ISOFF
SEROUT 0, T2400, ("VST", 13)
Light2 ISOFF
Pause 10000
Light1 ISON




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


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


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

michilson

just to clerify after i i looked at that post i dont want the sound file to pause i want the program to hold for the 15-20 sec while the sound file plays.

thanks

JonnyMac

I'm glad you're making the effort to write your own code and am now going to ask you to take the extra step in running it through the BASIC Stamp Editor before posting it.  Had you done that you would have found several, easily-correctable errors.

Now... I've made my position on the VMUSIC quite clear and what I demand, if you're going to ask for our help with it, is that you hook it up the way we tell you to.  That means two wires, not just one.  I've posted diagram to make the connections absolutely clear.

Here's my rewrite of your program -- it has been tested and is work on my little "VMUSIC lab."

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


' -----[ Program Description ]---------------------------------------------
'
' Demo for VMUSIC2 player
' -- P7 and P6 SETUP jumpers need to be in the UP position
' -- clip pins 1, 2 and 3 from ULN2803, or pin 1 and 2 from the ULN2003
' -- use P5 for Sio (no ULN) to EFX-TEK accessories
' -- use P4 for (active-high) trigger
'
' After downloading the program cycle power on the Prop-1 to allow the
' Prop-1 and VMUSIC to sync up.


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


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

SYMBOL  RX              = 7                     ' SETUP = UP, no ULN
SYMBOL  TX              = 6                     ' SETUP = UP, no ULN
SYMBOL  Sio             = 5                     ' no ULN
SYMBOL  Trigger         = PIN4                  ' MUST HAVE ULN (pull-down)

SYMBOL  Fog             = PIN2
SYMBOL  Light2          = PIN1
SYMBOL  Light1          = PIN0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  VolMax          = 0
SYMBOL  VolMin          = $FE

SYMBOL  Baud            = OT2400


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

SYMBOL  timer           = B2
SYMBOL  mute            = B3                    ' mute level (0 = loudest)


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

Power_Up:
 PAUSE 2250                                    ' let VMUSIC power up
 GOSUB VM_Stop                                 ' stop if playing

Reset:
 PINS = %00000001                              ' preset IOs (L1 is on)
 DIRS = %00000111                              ' P0-P2 are outputs


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

 Light1 = IsOff
 PAUSE 200
 Light2 = IsOn

 SEROUT TX, Baud, ("VPF angel.mp3", 13)
 PAUSE 20000

 Fog = IsOn
 PAUSE 10000

 Fog = IsOff
 GOSUB VM_Stop

 Light2 = IsOff
 PAUSE 10000

 GOTO Reset


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

VM_Wait_Start :
 SERIN RX, Baud, ("T $")
 RETURN

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

VM_Stop:
 SEROUT TX, Baud, ("VST", 13)

 ' falls through to VM_Wait_Prompt
 ' -- ensures VM ready for command after we stop it

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

VM_Wait_Prompt:
 SERIN RX, Baud, (">")
 RETURN

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

' Pass mute (0 = loudest, 254 = muted) in "mute"

VM_Mute:
 mute = mute MAX VolMin                        ' limit per spec
 SEROUT TX, Baud, ("VSV ", #mute, 13)
 RETURN


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


Jon McPhalen
EFX-TEK Hollywood Office

michilson

I know the program code had a few mistakes (at work and didnt have access to the Pbasic)

Thanks so much for your help. I wired the Vmusic to a 3x3 plug that sits on 2 pins on the Prop1 Using scary terrys wiring spec's.

PIn 1 has Orange, Red, Black Wires.
Pin 2 has Yellow, Blank, Green Wires.

The demo program works just need help getting the PIR to trigger it.

Thanks for all your help. Are the chips easy to get from radioshack or a web electronics store so i have spares for when i want to have all the orginal options back?

JonnyMac

1) I made it clear that we only want use the VMUSIC one way -- I actually took the time to reprogram your code and test it; please us it without throwing Scary Terry into the mix; it's not fair to me or to him.

2) I'm locking this thread because you've violated our guidelines by attempting to change topics mid-steam.  I don't know what chips you're talking referring to but will respond to a detail question posted in it's own thread.
Jon McPhalen
EFX-TEK Hollywood Office