May 18, 2024, 03:21:31 AM

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.


Prop-1 program help

Started by Marcharius, October 22, 2010, 11:33:50 PM

Previous topic - Next topic

Marcharius

October 22, 2010, 11:33:50 PM Last Edit: October 22, 2010, 11:42:59 PM by Marcharius
I have found lots of great information on here, especially in getting my Vmusic2 to work (and it does fantastically). But I am still getting used to the pbasic language and small amount of memory available on the prop-1. I believe I have a program that will compile but is too large for the prop-1 by just a bit and need some help shrinking it. Hopefully this can be done otherwise I will go down to 1 scene which I have been able to already fit. My code is below.

' =========================================================================
'
'   File....... Vampire Hunter.bs1
'   Purpose.... cycle through 2 separate audio and light scenes
'   Author..... Abe
'   Started.... 10/02/2010
'
' =========================================================================

' -----[ Program Description ]---------------------------------------------
'The RC-4 is connected to 3 lights, one for each person in the scene and
'they are turned on depending on who is speaking at the time. The last RC-4
'connection controls the pneumatic on the Vampire Coffin Jumper. The
'program will cycle through each scene continually.
' -------------------------------------------------------------------------

' {$STAMP BS1}
' {$PBASIC 1.0}


' -----[ Constants ]-------------------------------------------------------
SYMBOL    IsOn      =1
SYMBOL    IsOff     =0
SYMBOL    autoBTN   =PIN0      'pressure mat
SYMBOL    autoTOG   =PIN1      'Pressure mat or button toggle switch
SYMBOL    manBTN    =PIN2      'control box button
SYMBOL    Vbaud     =OT2400    'Vmusic baud rate
SYMBOL    Rbaud     =OT2400    'RC-4 baud rate
SYMBOL    RC4adr    =%11       'RC-4 address
' -------------------------------------------------------------------------

' -----[ Variables ]-------------------------------------------------------
SYMBOL    audio     =B2        'counter to cycle through scenes
' -------------------------------------------------------------------------


audio = 0
PAUSE 5000
SEROUT 7,Vbaud, ("VST",13)  'stop all tracks on player
PAUSE 2000
SEROUT 7, Vbaud, ("VSV 0",13)  'set volume max on player
PAUSE 2000
SEROUT 7,Vbaud,("VPF BckGrnd.mp3",13)    'play BckGrnd file

SEROUT 6, Rbaud, ("!RC4", RC4adr, "X")  'turn off all relays

Main:

IF autoTOG = IsOn AND autoBTN = IsOn THEN Fire    'Check for mat trigger

IF autoTOG = IsOff AND manBTN = IsOn THEN Fire    'Check button trigger

GOTO Main


Fire:
audio = audio + 1             'audio counter to decide which scene to play

IF audio = 1 THEN Dialog2

IF audio = 2 THEN Scream

Dialog2:
SEROUT 7,Vbaud, ("VST",13)     'stop all tracks on player

PAUSE 2000

SEROUT 7,Vbaud,("VPF dialog2.mp3",13)    'play dialog2 file

PAUSE 2000

SEROUT 6, Rbaud, ("!RC4", RC4adr, "R", 1, 1)    'turn light on gravedigger

PAUSE 7500

SEROUT 6, Rbaud, ("!RC4", RC4adr, "R", 1, 0)    'turn light off gravedigger
SEROUT 6, Rbaud, ("!RC4", RC4adr, "R", 2, 1)    'turn light on Van Helsing

PAUSE 5500

SEROUT 6, Rbaud, ("!RC4", RC4adr, "R", 2, 0)    'turn light off Van Helsing
SEROUT 6, Rbaud, ("!RC4", RC4adr, "R", 1, 1)    'turn light on gravedigger

PAUSE 8500

SEROUT 6, Rbaud, ("!RC4", RC4adr, "R", 1, 0)    'all lights now off

PAUSE 5500

SEROUT 6, Rbaud, ("!RC4", RC4adr, "R", 3, 1)    'turn light on Vampire popper and
SEROUT 6, Rbaud, ("!RC4", RC4adr, "R", 4, 1)    'pop Vampire

PAUSE 10000

SEROUT 6, Rbaud, ("!RC4", RC4adr, "X")          'turn off all relays

SEROUT 7,Vbaud, ("VST",13)  'stop all tracks on player
PAUSE 2000
SEROUT 7,Vbaud,("VPF BckGrnd.mp3",13)    'play BckGrnd file

PAUSE 30000

GOTO Main


Scream:
SEROUT 7,Vbaud, ("VST",13)         'stop all tracks on player

PAUSE 2000

SEROUT 7,Vbaud,("VPF scream.mp3",13)    'play scream file

SEROUT 6, Rbaud, ("!RC4", RC4adr, "R", 3, 1)    'turn light on Vampire popper and
SEROUT 6, Rbaud, ("!RC4", RC4adr, "R", 4, 1)    'pop Vampire

SEROUT 6, Rbaud, ("!RC4", RC4adr, "X")          'turn off all relays

SEROUT 7,Vbaud, ("VST",13)  'stop all tracks on player
PAUSE 2000
SEROUT 7,Vbaud,("VPF BckGrnd.mp3",13)    'play BckGrnd file

audio = 0      'resets scene counter to go back to dialog2 scene

PAUSE 30000

GOTO Main


BigRez

I don't like posting code without testing it, but unfortunately all my prop-1 devices are installed and ready to go so I can't test this.  Also, this post should probably belong in the Prop-1 forum rather than the Programming Techniques.

Anyway, give this a try - it may need some tweaking but it does fit into the prop-1 memory space.

' =========================================================================
'
'   File....... Vampire Hunter.bs1
'   Purpose.... cycle through 2 separate audio and light scenes
'   Author..... Abe
'   Started.... 10/02/2010
'
' =========================================================================

' -----[ Program Description ]---------------------------------------------
'The RC-4 is connected to 3 lights, one for each person in the scene and
'they are turned on depending on who is speaking at the time. The last RC-4
'connection controls the pneumatic on the Vampire Coffin Jumper. The
'program will cycle through each scene continually.
' -------------------------------------------------------------------------

' {$STAMP BS1}
' {$PBASIC 1.0}

' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL    Sio       = 6
SYMBOL    autoBTN   =PIN0      'pressure mat
SYMBOL    autoTOG   =PIN1      'Pressure mat or button toggle switch
SYMBOL    manBTN    =PIN2      'control box button


' -----[ Constants ]-------------------------------------------------------
SYMBOL    IsOn      =1
SYMBOL    IsOff     =0
SYMBOL    Vbaud     =OT2400    'Vmusic baud rate
SYMBOL    Rbaud     =OT2400    'RC-4 baud rate
SYMBOL    RC4adr    =%11       'RC-4 address


' -----[ Variables ]-------------------------------------------------------
SYMBOL    relays    = B0          '%0000      Each relays bit represents a device
SYMBOL      GDLight   =  BIT0     ' |||^----- GraveDigger Light
SYMBOL      VHLight   =  BIT1     ' ||^------ Van Helsing Light
SYMBOL      VampLight =  BIT2     ' |^------- Vampire Light
SYMBOL      VampPop   =  BIT3     ' ^-------- Vampire Popup

SYMBOL  audio       = B2        'counter to cycle through scenes
SYMBOL  timer1      = B3
SYMBOL  timer2      = B4


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

audio = 0
GOSUB VM_Stop
SEROUT 7, Vbaud, ("VSV 0",13)  'set volume max on player
PAUSE 2000

Main:
   GOSUB Play_BKGRND                                      ' note: includes a 30 second pause
   timer1 = 0
   timer2 = 0

Check_Trigger:                                            ' added debounce routine
   PAUSE 5                                                ' loop pad
   timer1 = timer1 + 5 * autoTOG                          ' update timer1
   timer2 = timer2 + 5 * autoBTN                          ' update timer2
   IF timer1 < 150 AND timer2 < 150 THEN Check_Trigger    ' wait for 0.15 sec input

   audio = audio + 1                             'audio counter to decide which scene to play

   IF audio = 2 THEN Scream                      ' If scene 2, go to screem otherwise fall-through

Dialog:
   GOSUB VM_Stop                            ' Stop VM from playing
   SEROUT 7,Vbaud,("VPF dialog2",13)        'play dialog2 file
   PAUSE 2000

   relays = %0001                           'turn light on gravedigger
   GOSUB Set_RC4                            ' Call RC4 routine
   PAUSE 7500

   relays = %0010                           'turn light on Van Helsing, off gravedigger
   GOSUB Set_RC4
   PAUSE 5500

   relays = %0001                           'turn light off Van Helsing, on gravedigger
   GOSUB Set_RC4
   PAUSE 8500

   GOSUB RC4_off                            ' Turn off all RC4 items
   PAUSE 5500

   relays = %1100                           'turn light on Vampire popper and pop Vampire
   GOSUB Set_RC4                            'Note: gravedigger also on

   PAUSE 10000                              ' IS THIS NEEDED? There's a 30 second pause when BckGrnd is played
   GOTO Main


Scream:
   GOSUB VM_Stop
   SEROUT 7,Vbaud,("VPF scream",13)         'play scream file

   relays = %1100                           'turn light on Vampire popper and pop Vampire
   GOSUB Set_RC4                            'Note: gravedigger also on

   'Shouldn't there be some sort of pause here???

   audio = 0                                'resets scene counter to go back to dialog2 scene
   GOTO Main

RC4_Off:
  relays = %0000
Set_RC4:
  SEROUT Sio, RBaud, ("!RC4", RC4adr, "S", relays)
  RETURN


Play_BKGRND:
   GOSUB RC4_Off                            ' turn off all RC4 items
   GOSUB VM_Stop                            ' stop VM playing
   SEROUT 7,Vbaud,("VPF BckGrnd",13)        ' play BckGrnd file
   PAUSE 30000
   RETURN

VM_Stop:
   SEROUT 7,Vbaud, ("VST",13)               ' stop all tracks on player
   PAUSE 2000
   RETURN

Marcharius

October 23, 2010, 07:47:39 AM #2 Last Edit: October 23, 2010, 07:53:49 AM by Marcharius
Hmm I see what you have done, and what I should have been doing all along. Subroutines for each RC-4 and Vmusic action so they are only in the code once. I will test this out as soon as I get a chance. One more quick question, the BckGrnd sound file is about 5 min long how can I play it and keep checking for triggers without replaying it until it is about done? I do not want to get into receiving anything from the Vmusic player.

JonnyMac

October 23, 2010, 09:51:35 AM #3 Last Edit: October 23, 2010, 09:53:39 AM by JonnyMac
Here's my version -- compiles, but not tested.  It fits with a tiny bit of room left, so be careful with any adjustments.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  TX              = 7                     ' SETUP = UP; no ULN
SYMBOL  Sio             = 6                     ' SETUP = UP; no ULN

SYMBOL  ManBtn          =  PIN2
SYMBOL  AutoTog         =  PIN1
SYMBOL  AutoBtn         =  PIN0                 ' active-high on P0

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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  relays          = B0

SYMBOL  triggers        = B2
SYMBOL  audio           = B3
SYMBOL  theMP3          = B4
SYMBOL  idx             = B5
SYMBOL  eePntr          = B6

SYMBOL  timer           = W5


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

Reset:
 PAUSE 2250                                    ' let VMUSIC power up
 relays = IsOff
 GOSUB Set_RC4
 GOTO Pgm_Delay


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

Main:
 triggers = PINS & %111                        ' mask inputs
 IF triggers = %011 THEN Fire                  ' AutoBtn + AutoTog
 IF triggers = %100 THEN Fire                  ' ManBtn
 GOTO Main

Fire:
 audio = audio + 1
 IF audio = 1 THEN Dialog2
 IF audio = 2 THEN Scream

Dialog2:
 theMP3 = 1
 GOSUB Play_MP3
 PAUSE 2000

 eePntr = 0                                    ' top of show
 FOR idx = 1 TO 5                              ' steps in show
   READ eePntr, relays                         ' get RC-4 bits
   eePntr = eePntr + 1
   READ eePntr, timer                          ' get timing
   eePntr = eePntr + 1
   GOSUB Set_RC4                               ' update RC-4
   timer = timer * 100                         ' convert to ms
   PAUSE timer                                 ' hold
 NEXT

 GOTO Pgm_Delay


Scream:
 theMP3 = 2
 GOSUB Play_MP3
 PAUSE 2000

 relays = %1100
 GOSUB Set_RC4
 PAUSE 5000                                    ' adjust for scream
  relays = IsOff
  GOSUB Set_RC4

 audio = 0


Pgm_Delay:
 theMP3 = 0
 GOSUB Play_MP3
 PAUSE 30000
 GOTO Main


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

' Sets RC-4 outputs to bits in 'relays'

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

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

' Stops player and starts new audio (if 'theMP3' is valid)

Play_MP3:
 SEROUT TX, Baud, ("VST", 13)                  ' stop player
 PAUSE 2000
 BRANCH theMP3, (Play_0, Play_1, Play_2)
 RETURN                                        ' bad file #

Play_0:
 SEROUT TX, Baud,("VPF bckgrnd.mp3", 13)
 RETURN

Play_1:
 SEROUT TX, Baud,("VPF dialog2.mp3", 13)
 RETURN

Play_2:
 SEROUT TX, Baud,("VPF scream.mp3", 13)
 RETURN

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

Dialog_Show:
 EEPROM (%0001,  75)                           ' grave digger
 EEPROM (%0010,  55)                           ' Van Helsing
 EEPROM (%0001,  85)                           ' grave digger
 EEPROM (%0000,  55)                           ' all off
 EEPROM (%1100, 100)                           ' vampire (pop + light)
Jon McPhalen
EFX-TEK Hollywood Office

Marcharius

I'm not sure I understand all of this one, so I'm going to study it some more before I try it. But I did slightly modify the other and fits, I'll let you guys know how it works after I test it. Thanks for all of the help.

JonnyMac

PBASIC can be a little daunting (at first) for those who come from PC programming backgrounds, especially PBASIC 1 as it is designed to be efficient in a very small memory footprint (256 total bytes of programming space).

Tip: Double-click a keyword (syntax color is blue) in the editor to highlight it and then press the [F1] key -- that will take you right to the page in the help file that explains the keyword.
Jon McPhalen
EFX-TEK Hollywood Office

Marcharius

After testing, the triggers are not working properly on either of these. The trigger part does work however on my initial program that does not fit. I ran a debug program with just the if statements to be sure there was no issue with my wiring. I'm still open to suggestions but I will try to figure this out.

JonnyMac

Create a little program that just has this section so you can see your inputs:

Main:
  triggers = PINS & %111                        ' mask inputs
  DEBUG %triggers
  GOTO Main


You should get %00000011 when you have your auto buttons pressed, and %00000100 when your manual button is pressed.
Jon McPhalen
EFX-TEK Hollywood Office

Marcharius

I do officially have an issue with my pressure mat, but am still working to resolve the programming issue on the manual button.

Marcharius

October 24, 2010, 10:30:47 AM #9 Last Edit: October 24, 2010, 10:37:09 AM by Marcharius
As far as the small button tester program, I get a constant trigger regardless of where the toggle is or whether or not any buttons are pressed. My if if statements give the effect I want i.e. forcing the program to look either for a pressure mat activation or a button activation, though I suppose those if statements eat up a lot of memory.

Edit- never mind I'm an idiot, Johnny your triggers work fine, thanks again for your help.

Marcharius

Sorry for all of the posts, the program is working great and i just need to fine tune the timing. I believe I understand enough of Johnny's program to be able to modify the times but is not I know where to go. Thanks again guys.

JonnyMac

If you're referring to the "dialog" section the timing is embedded in an EEPROM table at the end of the listing.  The first value in the line is the RC-4 outputs status, the second line is how long to hold them (in 100ms units).  This table was derived from your original code.  It's not as easy to read, but it does squeeze the behavior you want into a smaller space.
Jon McPhalen
EFX-TEK Hollywood Office

Marcharius

October 25, 2010, 08:00:44 PM #12 Last Edit: October 25, 2010, 08:06:14 PM by Marcharius
Yeah I think I have it figured out. After testing I did notice that the RC-4 relays do not reset to off after the dialog scene so I end up with one light still on and my prop still extended until I run it through again and they will turn off after the scream scene. I think this code bit of code added in should fix it.

Dialog2:
  theMP3 = 1
  GOSUB Play_MP3

  eePntr = 0                                    ' top of show
  FOR idx = 1 TO 5                              ' steps in show
    READ eePntr, relays                         ' get RC-4 bits
    eePntr = eePntr + 1
    READ eePntr, timer                          ' get timing
    eePntr = eePntr + 1
    GOSUB Set_RC4                               ' update RC-4
    timer = timer * 100                         ' convert to ms
    PAUSE timer                                 ' hold
  NEXT

  relays = IsOff
  GOSUB Set_RC4


  GOTO Pgm_Delay

BigRez

Yes that change will work, but knowing you're very tight on space, I would move the two existing lines

relays = IsOff
GOSUB Set_RC4

from within the Scream section down into the Pgm_Delay section.   This will allow both sections to turn off the RC4 relays with the same two lines of code.  Also, to save you a three more bytes (in case you need it), you can remove the entire line

IF audio = 1 THEN Dialog2

from the program.  Logically, it isn't needed because the value of audio is either 1 or 2 and if 1, it'll just fall through to the correct area. (Note that if you add another section, you'll need to add a new "IF" statement.)

bsnut

October 26, 2010, 12:32:03 AM #14 Last Edit: October 26, 2010, 12:36:56 AM by bsnut
What you did, does fit into the little bit of EEPROM that is left. But, there is one disadvantage by doing this, if you want add anything to the EEPROM (add to the show) you my not be able to do so and it will take up the EEPROM that you have left. Right now, with what you have done, you are at 98%. This means that you have 2% left to work with. Jon condensed your program down and when he did so, he was able get it to 96%. This means you have 4% left to add what you want to EEPROM in Dialog_Show

Give this small change below a try. It should take of your problem that you have

Dialog_Show:
 EEPROM (%0001,  75)                           ' grave digger
 EEPROM (%0010,  55)                           ' Van Helsing
 EEPROM (%0001,  85)                           ' grave digger
 EEPROM (%0000,  55)                           ' all off
 EEPROM (%1100, 100)                          ' vampire (pop + light)
   
William Stefan
The Basic Stamp Nut