May 20, 2024, 07:05:56 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Programming Zombie

Started by JonnyMac, October 31, 2009, 05:57:09 PM

Previous topic - Next topic

JonnyMac

... is exactly what I am after the last two weeks!  Since I had no time to do up a really cool costume I'm going to sew a Prop-1 to my EFX-TEK pull-over and run this program in it.  The Prop-1 is run from a 9v battery and, of course, a Trainer takes care of the IO.

Well, time to jump in the shower and start on the zombie make-up.  Happy Halloween!

' =========================================================================
'
'   File...... Programming_Zomibie.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...
'   Updated... 31 OCT 2009 -- yeah, last minute for a costume
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Speed   :: Pot on Prop-1 Trainer
'            -- 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  Speed           = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  LEDs            = PINS


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  state           = B2
SYMBOL  sub             = B3
SYMBOL  eePntr          = B4
SYMBOL  idx             = B5

SYMBOL  delay           = W4
SYMBOL  lottery         = W5


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

Reset:
 PINS = %00000000                              ' clear all
 DIRS = %00111111                              ' set output pins

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

Main:
 RANDOM lottery
 IF Trigger = IsOff THEN Handle_State
   PINS = IsOff
   state = state + 1 // 5                      ' update state
   sub = 0                                     ' reset substate

Release:
 IF Trigger = IsOn THEN Release


Handle_State:
 BRANCH state, (Zip, Bounce, Snake, Police, Crazy)
 state = 0

Zip:
 eePntr = 0 + sub
 sub = sub + 1 // 6
 GOTO Update_Leds


Bounce:
 eePntr = 6 + sub
 sub = sub + 1 // 10
 GOTO Update_Leds


Snake:
 eePntr = 16 + sub
 sub = sub + 1 // 12
 GOTO Update_Leds


Police:
 eePntr = 28 + sub
 sub = sub + 1 // 6
 GOTO Update_Leds


Crazy:
 FOR idx = 1 TO 3                              ' big scramble
   RANDOM lottery
 NEXT
 LEDs = lottery & %00111111
 GOTO Adjust_Speed


Update_Leds:
 READ eePntr, PINS


Adjust_Speed:
 POT Speed, 108, delay
 delay = delay + 45
 PAUSE delay
 GOTO Main


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


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

State_0:
 EEPROM (%000001, %000010, %000100, %001000, %010000, %100000)

State_1:
 EEPROM (%000001, %000010, %000100, %001000, %010000)
 EEPROM (%100000, %010000, %001000, %000100, %000010)

State_2:
 EEPROM (%000001, %000011, %000111, %001111, %011111, %111111)
 EEPROM (%111110, %111100, %111000, %110000, %100000, %000000)

State_3:
 EEPROM (%011001, %111000, %011001, %100110, %000111, %100110)


Jon McPhalen
EFX-TEK Hollywood Office