November 22, 2024, 04:55:26 AM

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.


RMG Casa de Fear Zombie

Started by uncle, June 17, 2009, 10:59:00 AM

Previous topic - Next topic

John Wohlers

Jon,  if I wanted to make one of the pins (PIN 2) go high on trigger and stay high during the random triggering, so I could then later fade it down (for use with an LED spotlight) after the thrashing is finished how would I go about this?

I had thought I could just OR the 'valves' value with the number 4 (which would be bitwise 00000100 ) before the "PINS = valves" line but that didn't seem to work.   

John \/\/ohlers

JonnyMac

October 17, 2009, 09:48:33 PM #16 Last Edit: October 23, 2009, 12:23:18 AM by JonnyMac
John,

You need to make the pin an output for that to work, so the DIRS line at the top has to be adjusted.  

Here's an update of the last version of the program in this thread with eyes that flash on in the beginning and fade out at the end.  You'll have to adjust the FOR-NEXT STEP value or the PWM cycles value to get the fade-out to your liking.

Updated: 22 OCT 2009

' =========================================================================
'
'   File...... Zombie_Thrasher_3x.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 22 OCT 2009 (JW)
'
'   {$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 and 2 from ULN2803, or pin 1 from the ULN2003
' -- use P5 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  Trigger         = PIN5                  ' MUST HAVE ULN (pull-down)

SYMBOL  Eyes            = 2
SYMBOL  Shoulder2       = PIN1                  ' use V+/OUT1 terminals
SYMBOL  Shoulder1       = PIN0                  ' use V+/OUT0 terminals


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  idx             = B0
SYMBOL  valves          = B1
SYMBOL  last            = B2
SYMBOL  mask            = B3
SYMBOL  check           = B4
SYMBOL  playlist        = B5

SYMBOL  delay           = W3
SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Power_Up:
 PAUSE 2500                                    ' allow VMUSIC to power up
 GOSUB VM_Stop                                 ' stop if playing

Reset:
 PINS = %00000000                              ' clear IO pins
 DIRS = %00000111                              ' set P0, P2, P2 as outs

 PAUSE 30000                                   ' warm-up / reset delay


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

Main:
 DEBUG CLS, "Ready", CR
 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
 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 Set_Length    ' finished?
     playList = %00000000                      ' yes, reset

Set_Length:
 LOOKUP idx, (51000, 31000, 9100), timer       ' set for show length

Start_Audio:
 idx = idx + "1"                               ' convert for file name
 DEBUG "zombie", #@idx, CR
 SEROUT TX, Baud, ("VPF zombie", idx, ".mp3", 13)
 GOSUB VM_Wait_Start
 PINS = %00000111                              ' shoulders and eyes on

 DEBUG "Thrashing", CR

Thrasher:
 RANDOM lottery
 RANDOM lottery
 RANDOM lottery
 valves = lottery & %00000011
 IF valves = last THEN Thrasher                ' no repeats
   last = valves                               ' save for next cycle
 PINS = valves | %00000100                     ' new shoulders + eyes
 RANDOM lottery                                ' re-stir
 delay = lottery // 251 + 100                  ' delay 100 to 350 ms
 PAUSE delay
 IF timer <= delay THEN Eyes_Die               ' done?
   timer = timer - delay                       ' no, update thrash time
   GOTO Thrasher

Eyes_Die:
  PINS = %00000111                              ' shoulders and eyes on
 FOR idx = 255 TO 0 STEP -1                    ' bigger step = faster
   PWM Eyes, idx, 1                            ' bigger cycles = slower
 NEXT

 GOTO Reset


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

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

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

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

John Wohlers

Thanks Jon, I had pin 2 set to output, but I just went back over my code and realized now I did something really dumb... 

Where you have:
PINS = valves | %00000100

I basically intended to do the same thing, but for some reason as I was working things out i replaced "valves" with the number 4.  So, I had

PINS = 4 | %00000100

I'm pretty sure i had started out with valves | 4 and then decided to do it using the bit mask for easier reading  but then erased the wrong part of the line in my haste.  which explains why the solenoids were not firing :-)

Thanks again for your excellent support!
John \/\/ohlers

uncle

Jon-

I am unable to get the multiple audio version (without eyes) to work.  I am able to get the prior single audio versions to work, but when I try this one I get just a momentary activation of 1 valve (slight "pop") and nothing else.  Could the idx be having problems with randomizing both audio files and run times?

JonnyMac

I couldn't find anything wrong with the listing -- but then, I couldn't make it work, either (yeah, I had to drag out that silly VMUSIC player).  At any rate, I rebuilt the 3x version (with eyes) from [nearly] scratch and ran it on my bench; the updated listing (above) is working the way it's intended to run.  Give it a try.
Jon McPhalen
EFX-TEK Hollywood Office

uncle

Jon-

It appears to be working (though the Debug Terminal pops up immediately after running the program in the editor). 

BigRez

October 23, 2009, 10:11:50 AM #21 Last Edit: October 23, 2009, 10:13:31 AM by bigrez
Take out or comment out the 3 debug lines (one in Main: and two in Start_Audio:) and the debug window will no longer appear.