May 02, 2024, 10:25:23 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.


Casa Fear Zombie Programming help

Started by halstaff, February 07, 2011, 02:26:47 PM

Previous topic - Next topic

halstaff

I was planning on running 3 different tracks, each of which would be about 15 seconds.

JonnyMac

Here's an update to what Brian posted that fixes a couple "gotchas" and allows you to connect an AP-8 through a serial link so you can have multiple files.

Important note: Due to the length of the segments in the AP-8 and the length of your zombie movement you need to start the sounds in slot 0, 3, and 6 -- this program expects that.

Fair warning: There's a lot going on here for your first walk in the forest of programming. I suggest you open the help file and read about the commands as you see them in context (i.e., used in your program) so that you can start to get the hang of it. PBASIC is a language, and as you learn to speak it you can learn to tell your Prop-1 exactly what you want it to do.

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


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; No ULN
SYMBOL  Trigger         = PIN6                  ' ULN is pull-down
SYMBOL  LED             = PIN3                  ' use V+/OUT3 terminals
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 serial

SYMBOL  ThrashTime      = 15000


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

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

SYMBOL  sfx             = B5
SYMBOL  lastsfx         = B6

SYMBOL  delay           = W4
SYMBOL  timer           = W5
SYMBOL  lottery         = W6


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

Power_Up:
 PAUSE 250

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

 SEROUT Sio, Baud, ("!AP8", %00, "X")          ' stop audio
 PAUSE 30000                                   ' 30s 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


Start_Audio:
 RANDOM lottery                                ' stir random #
 sfx = lottery // 3                            ' 0..2
 IF sfx = lastsfx THEN Start_Audio             ' don't repeat
   lastsfx = sfx                               ' save for next time

 sfx = sfx * 3                                 ' convert to slot #
 SEROUT Sio, Baud, ("!AP8", %00, "P", sfx)     ' start audio


Jump:
 PINS = %00001011                              ' led + shoulders on
 PAUSE 1000

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 | %00001000                     ' update shoulder outputs
 RANDOM lottery                                ' restir
 delay = lottery // 251 + 100                  ' delay 100 to 350 ms
 PAUSE delay
 timer = timer + delay                         ' update timer
 IF timer < ThrashTime THEN Thrasher           ' thrash for 10 seconds
   GOTO Reset
Jon McPhalen
EFX-TEK Hollywood Office

halstaff

Thanks.  That looks great!
I've been reading the primers and many of the threads and it's starting to make sense.  The Random code is something I hadn't seen before though.
The audio settings make sense and that's part of the reason I was going with the time settings I choose.
I'll load this up when I get home tonight as my order for the programming cables arrived yesterday.  Yea!
Steve

halstaff

Just wanted to thank everyone for patiently walking me through my first project using a Prop1.  I got everything loaded and hooked up and it works great!  I'm not pleased with the audio I'm getting from the thrift shop speakers I picked up today but other than that I'm happy with the results.
I can now move this guy to the other side of my graveyard as he's no longer tied to my EZ-8. 

bsnut

I am glad you are happy with your first project. This also gives you an idea how a program is coded and I agree with Jon in his last post.
William Stefan
The Basic Stamp Nut