November 21, 2024, 04:35:30 PM

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.


RMG Casa de Fear Zombie

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

Previous topic - Next topic

uncle

Jon-

I have been shamelessly modifying your program to include the VMusic module.  Unfortunately I am not currently near a Prop-1 to test it, but I would appreciate if you wuld review it when you have a moment and let me know if there are any problems or changes that could be made.

The additional notations I added just as notes for myself.

And thanks again for the original program!

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


' -----[ Program Description ]---------------------------------------------
'
' Sio     :: Serial IO to EFX-TEK accessories (RC-4, FC-4, etc.)
'            -- clip pin 1 of ULN2803 or replace with ULN2003
'
' Trigger :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'            -- connect N.O. button between P6.W and P6.R


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


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

SYMBOL  Rx      = 7      ' SETUP = UP; no ULN pin
SYMBOL  Tx      = 6      ' SETUP = UP; no ULN pin
SYMBOL  Trigger      = PIN5      ' SETUP = DN
SYMBOL  LShoulder      = PIN1      ' use V+ and OUT1 screw terminals
SYMBOL  RShoulder      = PIN0      ' use V+ and OUT0 screw terminals


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

SYMBOL  IsOn            = 1         ' for active-high in/out
SYMBOL  IsOff           = 0         ' put back to low/off

SYMBOL  Yes             = 1         '
SYMBOL  No              = 0         '

SYMBOL  Baud   = OT2400                      ' set baud for VMusic


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

SYMBOL  lottery   = W0

SYMBOL  timer   = W1
SYMBOL  delay   = W2

SYMBOL  idx   = B6
SYMBOL  valves   = B7
SYMBOL  last   = B8


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

Reset:
  PINS = %00000000            ' reset all I/O pins to 0 or low/off state
  DIRS = %00000011            ' sets Out0 and OUT1 as High(1)= as outputs


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


  PAUSE 10000               ' 10 second pause


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

Main:
  timer = 0               ' reset timer

Check_Trigger:
  RANDOM lottery               ' randomize lottery value
  PAUSE 5                  ' loop pad
  timer = timer + 5 * Trigger         ' update timer- note trigger is 1 or 0
  IF timer < 100 THEN Check_Trigger      ' wait for 0.1 sec input

Jump:
  PINS = %00000011            ' sets PINS0 and PINS1 as HIGH/on state
  PAUSE 1000               ' 1 second pause

  timer = 0                  ' reset timer value to 0

Audio_Activate:
  SEROUT TX, Baud, ("VPF file1.mp3", 13)
  GOSUB VM_Wait_Start
  PAUSE 100               ' pause inserted in case want to adjust

Thrasher:
  FOR idx = 1 TO 3
    RANDOM lottery
  NEXT
  valves = lottery & %00000011

  IF valves = last THEN Thrasher      ' no repeats
    last = valves               ' save for next cycle

  PINS = valves
  RANDOM lottery
  delay = lottery // 251 + 100
  PAUSE delay
  timer = timer + delay
  IF timer < 10000 THEN Thrasher
    GOTO Reset


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

JonnyMac

June 17, 2009, 11:58:52 AM #1 Last Edit: June 17, 2009, 12:02:49 PM by JonnyMac
Here's my minor cleanup.  Keep in mind that you don't need to provide comments to code that is obvious -- it's just more typing that you need to do.


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


' -----[ Program Description ]---------------------------------------------
'
' Trigger :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'            -- connect N.O. button between P5.W and P5.R
'
'
' After downloading this program you should cycle power on the Prop-1 to
' allow synchronization with the VMUSIC player.


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


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

SYMBOL  RX              = 7                     ' SETUP = UP; no ULN pin
SYMBOL  TX              = 6                     ' SETUP = UP; no ULN pin
SYMBOL  Trigger         = PIN5                  ' ULN is pull-down
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                     ' put back to low/off

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' baud for VMusic


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

SYMBOL  idx             = B2
SYMBOL  valves          = B3
SYMBOL  last            = B4

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


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

Power_Up:
  PAUSE 2250                                    ' let VMUSIC power up

Reset:
  PINS = %00000000                              ' preset IO pins
  DIRS = %00000011                              ' define IO pins

  GOSUB VM_Stop                                 ' stop if playing
  GOSUB VM_Wait_Prompt

  PAUSE 10000                                   ' 10s inter-show delay


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' randomize lottery value
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' inc or clear timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

Jump:
  PINS = %00000011                              ' both shoulders on
  PAUSE 1000                                    ' adjust for audio

Audio_Activate:
  SEROUT TX, Baud, ("VPF zombie.mp3", 13)
  GOSUB VM_Wait_Start
  PAUSE 100                                     ' adjust for audio

  timer = 0                                     ' reset timer

Thrasher:
  FOR idx = 1 TO 3                              ' big stir
    RANDOM lottery
  NEXT
  valves = lottery & %00000011

  IF valves = last THEN Thrasher                ' no repeats
    last = valves                               ' save for next cycle

  PINS = valves                                 ' update should outputs
  RANDOM lottery                                ' restir
  delay = lottery // 251 + 100                  ' delay 100 to 350 ms
  PAUSE delay
  timer = timer + delay                         ' update timer
  IF timer < 10000 THEN Thrasher                ' thrash for 10 seconds
    GOTO Reset


' -----[ 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 ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

uncle

Thanks Jon!  I just like to insert the "obvious" comments for future use.  Not being a programmer, I tend to forget what even the obvious means if I haven't been working on a project for a few months.

uncle

Jon-

I am just a little unclear on what to do when you say in the description that we need to cycle power on the Prop-1 after downloading.  Is that referring to the PAUSE 2250 or that that we need to turn on, download, and then turn off or?

JonnyMac

Yes.  The reason for this is to get the Prop-1 in sync with the VMUSIC.  Since the Prop-1 can't do a serial timeout if it misses the response from the VMUSIC then the program will stick; I saw this the other day.  Cycling power did the trick.  With the Prop-2 we can do a timeout which will allow us to re-ping the VMUSIC to get it to wake up.

Once the unit is in sync it will stay in sync.
Jon McPhalen
EFX-TEK Hollywood Office

uncle

Jon-

One of our members here at Rocky Mountain Haunters wondered if this program could be modified to just run the zombie randomly throughout the night without waiting for a trigger signal?  I wish I could say I had a clue how to replace the check trigger portion of the code with a random activation sequence, but I have been having nothing but brain cramps.

JonnyMac

Of course it can, but I need to know what kind of delays (minimum and maximum) you want between activations.
Jon McPhalen
EFX-TEK Hollywood Office

uncle

I have been wondering the same thing since he mentioned the idea.  I am thinking possibly a maximum of 5 minutes and a minimum of 1 minute might work. 

JonnyMac

September 16, 2009, 12:46:59 PM #8 Last Edit: September 16, 2009, 02:19:01 PM by JonnyMac
Here you go.  Adjust MIN_DELAY and MAX_DELAY (both expressed in seconds) as needed.  Note that lottery is "seeded" in the Power_Up section.  If you have multiple zombies on the same power system you will want to change the initial seed value in each zombie, otherwise they will "randomly" come on pretty much at the same time -- this is because RANDOM is actually pseudo-random and the same seed in gives the same result out.

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


' -----[ Program Description ]---------------------------------------------
'
' Trigger :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'            -- connect N.O. button between P5.W and P5.R
'
' After downloading this program you should cycle power on the Prop-1 to
' allow synchronization with the VMUSIC player.


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


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

SYMBOL  RX              = 7                     ' SETUP = UP; no ULN pin
SYMBOL  TX              = 6                     ' SETUP = UP; no ULN pin
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                     ' put back to low/off

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' baud for VMusic

SYMBOL  MIN_DELAY       = 60                    ' 60 seconds
SYMBOL  MAX_DELAY       = 300                   ' 300 seconds (5 mins)


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

SYMBOL  idx             = B2
SYMBOL  valves          = B3
SYMBOL  last            = B4

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


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

Power_Up:
 PAUSE 2250                                    ' let VMUSIC power up

 lottery = 1031                                ' seed BEFORE Reset


Reset:
 PINS = %00000000                              ' preset IO pins
 DIRS = %00000011                              ' define IO pins

 GOSUB VM_Stop                                 ' stop if playing
 GOSUB VM_Wait_Prompt


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

Main:
 RANDOM lottery                                ' stir random
 timer = MAX_DELAY - MIN_DELAY + 1             ' get span
 timer = lottery // timer + MIN_DELAY          ' randomize delay (secs)

Show_Delay:
 IF timer = 0 THEN Jump                        ' if expired, jump
   PAUSE 1000                                  ' wait 1s
   timer = timer - 1                           ' update timer
   GOTO Show_Delay                             ' check again

Jump:
 PINS = %00000011                              ' both shoulders on
 PAUSE 1000                                    ' adjust for audio

Audio_Activate:
 SEROUT TX, Baud, ("VPF zombie.mp3", 13)
 GOSUB VM_Wait_Start
 PAUSE 100                                     ' adjust for audio

 timer = 0                                     ' reset timer

Thrasher:
 FOR idx = 1 TO 3                              ' big stir
   RANDOM lottery
 NEXT
 valves = lottery & %00000011

 IF valves = last THEN Thrasher                ' no repeats
   last = valves                               ' save for next cycle

 PINS = valves                                 ' update should outputs
 RANDOM lottery                                ' restir
 delay = lottery // 251 + 100                  ' delay 100 to 350 ms
 PAUSE delay
 timer = timer + delay                         ' update timer
 IF timer < 10000 THEN Thrasher                ' thrash for 10 seconds
   GOTO Reset


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

Jon McPhalen
EFX-TEK Hollywood Office

uncle

Thanks Jon!  You guys are always the best!!

Deathstalker

I too am using this zombie program to run mine Jon (Thank you very much), if I were to want to have X number of sound clips that would play at random with this code, and have the zombie start & stop thrashing when the sound clip starts & stops, can you give me a hint on how to modify this?"

JonnyMac

@Deathstalker: Your request is for a new program -- well, a major change -- so please start a new thread and give me all the details, i.e., what sound player are you using?  If not an AP-8, how do you select an individual file?  How many files are there?  What are the names?

As I keep reminding my friends, I skipped class on the day mind-reading was taught and am too tired to guess.
Jon McPhalen
EFX-TEK Hollywood Office

uncle

Jon-

I have attempted to modify the program to have it randomly choose 1 of 3 different sequences (each sequence has a different audio file and slightly different thrash time).  I considered attempting to use more subroutines, but knew I would get myself totally confused (instead of just mostly...).  Would you mind looking it over and letting me know where I have botched things?

' =========================================================================
'
'   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 Jumper = UP, no ULN
SYMBOL  TX         = 6         ' SETUP Jumper = UP, no ULN
SYMBOL  Trigger                      = PIN5         ' active-high input; mat switch Red and White Pin5
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         ' put back to low/off

SYMBOL  Yes         = 1
SYMBOL  No         = 0

SYMBOL  IsUp         = 1
SYMBOL  IsDown                      = 0

SYMBOL  Baud         = OT2400                     ' VMusic baud rate is True 2400


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

SYMBOL  idx         = B2
SYMBOL  valves                      = B3
SYMBOL  last         = B4
SYMBOL  mask         = B5
SYMBOL  check         = B6
SYMBOL  playlist                      = B7

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


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

Power_Up:
 PAUSE 2250                                                                                           ' allow VMUSIC to power up

Reset:
 GOSUB VM_Stop                                                                                    ' stop if playing
 GOSUB VM_Wait_Prompt

 PINS = %00000000                                                                               ' clear IO pins
 DIRS = %00000011                                                                               ' Define IO Pins; OUT0,1 as output


' -----[ 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:
 PINS = %00000011                                                                             ' both shoulders on
 PAUSE 1000                                                                                         ' adjust for audio
 SEROUT TX, Baud, ("VPF zombie1.mp3", 13)                                 ' play zombie1.mp3 audio file
 GOSUB VM_Wait_Start
 PAUSE 100                                                                                           ' adjust for audio
 timer = 0                                                                                              ' reset timer
 FOR idx = 1 TO 3                                                                                  ' big stir
   RANDOM lottery
 NEXT
 valves = lottery & %00000011
 IF valves = last THEN Thrasher                                                            ' no repeats
   last = valves                                                                                      ' save for next cycle
 PINS = valves                                                                                      ' update shoulder outputs
 RANDOM lottery                                                                                   ' re-stir
 delay = lottery // 251 + 100                                                                ' delay 100 to 350 ms
 PAUSE delay
 timer = timer + delay                                                                           ' update timer
 IF timer < 10000 THEN Thrasher                                                         ' 10 second thrash time for Seq1
 PAUSE 30000
   GOTO Reset


Seq2:
 PINS = %00000011                                                                            ' both shoulders on
 PAUSE 1000                                                                                        ' adjust for audio
 SEROUT TX, Baud, ("VPF zombie2.mp3", 13)                                ' play zombie2.mp3 audio file
 GOSUB VM_Wait_Start
 PAUSE 100                                                                                          ' adjust for audio
 timer = 0                                                                                             ' reset timer
 FOR idx = 1 TO 3                                                                                 ' big stir
   RANDOM lottery
 NEXT
 valves = lottery & %00000011
 IF valves = last THEN Thrasher                                                           ' no repeats
   last = valves                                                                                     ' save for next cycle
 PINS = valves                                                                                     ' update shoulder outputs
 RANDOM lottery                                                                                  ' re-stir
 delay = lottery // 251 + 100                                                               ' delay 100 to 350 ms
 PAUSE delay
 timer = timer + delay                                                                          ' update timer
 IF timer < 15000 THEN Thrasher                                                        ' 15 second thrash time for Seq2
 PAUSE 30000
   GOTO Reset


Seq3:
 PINS = %00000011                                                                             ' both shoulders on
 PAUSE 1000                                                                                         ' adjust for audio
 SEROUT TX, Baud, ("VPF zombie3.mp3", 13)                                       ' play zombie3.mp3 audio file
 GOSUB VM_Wait_Start
 PAUSE 100                                                                                          ' adjust for audio
 timer = 0                                                                                             ' reset timer
 FOR idx = 1 TO 3                                                                                 ' big stir
   RANDOM lottery
 NEXT
 valves = lottery & %00000011
 IF valves = last THEN Thrasher                                                           ' no repeats
   last = valves                                                                                     ' save for next cycle
 PINS = valves                                                                                     ' update shoulder outputs
 RANDOM lottery                                                                                  ' re-stir
 delay = lottery // 251 + 100                                                               ' delay 100 to 350 ms
 PAUSE delay
 timer = timer + delay                                                                          ' update timer
 IF timer < 5000 THEN Thrasher                                                          ' 5 second thrash time for Seq3
 PAUSE 30000
   GOTO Reset

 

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

JonnyMac

Nice try -- but here are some things to keep in mind for next time:

1. The EEPROM is only so big; your program does not fit
2. Bx variables and Wx variables can occupy the same space -- your B6 and B7 are smashing into W3
    -- this can be okay in some programs, but B7 needs to be persistent so that doesn't work here
3. You're re-using "last" in two places for different events; a problem in this program (I removed the first one)

Here's my version of of the program -- see how I used LOOKUP to set the show time and the trick I did with SEROUT to play the audio file associated with the show.

' =========================================================================
'
'   File...... Zombie_Thrasher_3x.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 15 OCT 2009 (JW)
'
'   {$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  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                     ' put back to low/off

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0

SYMBOL  Baud            = T2400


' -----[ 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 2250                                    ' allow VMUSIC to power up

Reset:
  GOSUB VM_Stop                                 ' stop if playing
  GOSUB VM_Wait_Prompt

  PINS = %00000000                              ' clear IO pins
  DIRS = %00000011                              ' set P0 and P1 as outs

  PAUSE 30000                                   ' PIR warm-up/delay


' -----[ 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
  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 Jump          ' finished?
      playList = %00000000                      ' yes, reset

Jump:
  PINS = %00000011                              ' both shoulders on
  PAUSE 1000                                    ' adjust for audio

  LOOKUP idx, (1000, 2000, 3000), timer         ' set for show length

Start_Audio:
  idx = idx + "1"                               ' convert to ASCII
  SEROUT TX, Baud, ("VPF zombie", idx, ".mp3", 13)
  GOSUB VM_Wait_Start
  PAUSE 100

Thrasher:
  FOR idx = 1 TO 3                              ' big stir
    RANDOM lottery
  NEXT
  valves = lottery & %00000011
  IF valves = last THEN Thrasher                ' no repeats
    last = valves                               ' save for next cycle
  PINS = valves                                 ' update shoulder outputs
  RANDOM lottery                                ' re-stir
  delay = lottery // 251 + 100                  ' delay 100 to 350 ms
  PAUSE delay
  IF timer <= delay THEN Reset                  ' done?
    timer = timer - delay                       ' no, update thrash time
    GOTO Thrasher


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

Drat!  I was afraid I had a memory problem, and for some reason I didn't even notice I had that B6 B7 W3 problem (maybe I was looking at the Bit chart).  Oh well...

Thanks again for everything you guys do!!!!