November 22, 2024, 10:03:42 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.


VMusic, 12 volt solenoid

Started by uncle, October 16, 2008, 10:46:05 AM

Previous topic - Next topic

uncle

Jon-

I am working on a prop that would have the following sequences:

Sequence 1:
A.  Wait for Mat Switch trigger input
B.  Upon Input
               1. Play File1.mp3 for 30 seconds

Sequence 2:
A.  Wait for Mat Switch trigger input
B.  Upon Input
               1. Play File2.mp3 for 30 seconds

Sequence 3:
A.  Wait for Mat Switch trigger input
B.  Upon Input
               1. Play File3.mp3 for 30 seconds
               2. 20 seconds into File 3, activate 12 volt solenoid for 10 seconds to raise and lower air cylinder

But, I am wondering if there is a way to randomize the order of the sequences?

JonnyMac

So, if I understand, you have one mat switch that is used to randomly trigger three different events?
Jon McPhalen
EFX-TEK Hollywood Office

uncle

Yes.  A sequence runs and then there is a pause where the controller waits for the next mat switch event before running the next sequence,  and so on. 

However, only one of the sequences has both sound and solenoid activation.  So I am wondering if there is a way to randomize the sequences so that we never exactly know which sequence will be triggered next.

JonnyMac

October 17, 2008, 06:26:53 PM #3 Last Edit: October 24, 2008, 07:46:40 AM by JonnyMac
Give this a try.

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


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


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


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

SYMBOL  RX              = 7                     ' SETUP = UP, no ULN
SYMBOL  TX              = 6                     ' SETUP = UP, no ULN
SYMBOL  Trigger         = PIN5                  ' active-high input
SYMBOL  Cylinder        = PIN0                  ' use OUT0/V+


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

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

SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  timer           = B2
SYMBOL  idx             = B3
SYMBOL  last            = B4
SYMBOL  mask            = B5
SYMBOL  check           = B6
SYMBOL  playList        = B7

SYMBOL  lottery         = W5


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

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

  PINS = %00000000                              ' clear all
  DIRS = %00000001                              ' set outputs


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

Main:
  timer = 0                                     ' reset timer

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

Select_Sequence:
  RANDOM lottery                                ' re-stir random #
  idx = lottery // 3                            ' select, 0..2
  IF idx = last THEN Select_Sequence            ' no repeats
    last = idx                                  ' save for next cycle
  READ idx, mask                                ' convert to bit mask
  check = playList & mask                       ' check play list
  IF check <> %00000000 THEN Select_Sequence    ' try again if played
    playList = playList | mask                  ' mark play list
    IF playList <> %00000111 THEN Run_Sequence  ' finished?
      playList = %00000000                      ' yes, reset

Run_Sequence:
  BRANCH idx, (Seq1, Seq2, Seq3)

Seq1:
  SEROUT TX, Baud, ("VPF file1.mp3", 13)
  GOSUB VM_Wait_Start
  PAUSE 30000
  GOSUB VM_Stop
  GOTO Main

Seq2:
  SEROUT TX, Baud, ("VPF file2.mp3", 13)
  GOSUB VM_Wait_Start
  PAUSE 30000
  GOSUB VM_Stop
  GOTO Main

Seq3:
  SEROUT TX, Baud, ("VPF file3.mp3", 13)
  GOSUB VM_Wait_Start
  PAUSE 20000
  Cylinder = IsUp
  PAUSE 10000
  Cylinder = IsDown
  GOSUB VM_Stop
  GOTO Main


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

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

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

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

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

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


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

Bit_Mask:
EEPROM (%00000001, %00000010, %00000100, %00001000)
EEPROM (%00010000, %00100000, %01000000, %10000000)
Jon McPhalen
EFX-TEK Hollywood Office

uncle

Jon-

Unfortunately I cannot get this program to work.  I have tried the program below as a test of the connections etc, and it works, so I believe the connections, vmusic module, and controller are all working.


' =========================================================================
'
'   File....... Ghost Host.bs1
'   Purpose.... Play file on VMusic2 driven by a Prop-1
'   Author..... Mark Parry
'   Started.... 5/31/2008
'   Updated.... 10/22/2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
' Sends serial commands to the VMusic2 via the RXD input.  The following are the individual commands
' (note that 13 is a "carriage return):
' VPF file 13   Plays single file where "file" is MP3 name, MAXIMUM 8 CHARACTERS PLUS EXTENSION (8.3)
' VST 13        Stops play
' V3A 13        Plays all MP3 files
' VRA 13        Repeatedly plays all MP3 files
' VRR 13        Repeatedly plays random MP3 files
' VSF 13        Skip forward one track
' VSB 13        Skip back one track
' VP 13         Pause
' VSV byte 13   Sets playback volume, 0 loud, 256 off


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

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

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

SYMBOL Baud      = OT2400                       'The baud rate is 2400
SYMBOL  RX         = 7                                  ' SETUP = UP, no ULN
SYMBOL  TX         = 6                                  ' SETUP = UP, no ULN
SYMBOL  MatSw  = PIN5                             'mat switch Red and White on pin 5

SYMBOL No      = 0

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

' -----[ EEPROM Data ]-----------------------------------------------------


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

PAUSE 5000                                             'allow VMusic2 to initialize
SEROUT TX,Baud, ("VST",13)                    'stop anything that's playing

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

SEROUT TX,Baud, ("VSV 0",13)                  'Set volume to full
PAUSE 500                                                '.5 second delay

Main:
IF MatSw = No THEN Main                       ' wait for "victim"
PAUSE 300                                              ' .3 second delay

SEROUT TX,Baud,("VPF file1.mp3",13)    'Play file
PAUSE 30000                                          '30 second delay

GOTO Main
END

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

JonnyMac

Sorry, I had to write the program while I was traveling and couldn't test it on my own hardware.  I made a mistake: I used "mask" where I should have used "check" (see the line marked red, above).  I've run the program on my setup with that change and can vouch that it works.

Again, sorry about that.
Jon McPhalen
EFX-TEK Hollywood Office

uncle

Jon-

Don't apologize to me!  I can't express how much I appreciate the help you give us programming idiots!!  I just wish I knew programming so I didn't have to bother you at this time of year.

Course it would also be nice if the nephew didn't suddenly come up with these ideas for new props at the last minute.

I look forward to trying out the revised program tonight after work.

uncle

Jon-

I can get part of the program to work (audio), but only If I remove the following line from the program:

DIRS = %00111111                              ' set outputs

However, I get no voltage through the solenoid output terminals.  I am using the ULN2803 with the two pins removed and both jumpers in the up position.  Can you think of what I may be missing?

JonnyMac

Doggone my eyes -- I fixed two lines in your program but only told you about one.  Change that line to this:

  DIRS = %00000001

Man, I need some rest....
Jon McPhalen
EFX-TEK Hollywood Office