November 23, 2024, 08:32:58 PM

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.


template program

Started by Karl Fields, September 20, 2011, 01:11:33 AM

Previous topic - Next topic

Karl Fields

September 20, 2011, 01:11:33 AM Last Edit: September 20, 2011, 07:26:04 AM by JonnyMac
We are redoing all of the Prop1s at the haunt, and I would really like to start off with a template that I modify or tweek for each prop.
Years of 'modifying' other programs have left me with a mell of a hess every year :)

Requirements:
7 outputs, usually solenoids or relays, all 12-24vdc.
Each output would also have timer.
A couple of spare timers for controlling the overall flow.
A subroutine for a trigger. Most would use PIR, but some have buttons and still others will simply be timed events.
Maybe one of the outputs could be a sound card, and maybe even one of yours!
Thanks,
Karl



bsnut

September 21, 2011, 03:32:14 AM #1 Last Edit: September 21, 2011, 06:20:30 AM by bsnut
Jon has done an standard template program and you can find it at the top of the "Programming Techniques" forum and there is a sticky thread called "Using Templates with the Basic Stamp Editor" that you can change to meet your needs. This thread also shows you how set the template file in your Basic Stamp Editor, so you can start off with a clean template everytime you click File>New.
William Stefan
The Basic Stamp Nut

JonnyMac

As William pointed out, I've had a standard template -- that I use when getting customer requests -- posted in these forums for a long time.  The *danger* with "do everything" templates is that they're loaded with stuff you may not use which just takes space.  The standard programming template that we use covers 99% of all requests. 

That said, I created a derivative for you.  Note that you cannot have a timer per output; everything runs in one thread so you have to build changing outputs sequentially.  What I did do is create a set of timer subroutines that you can choose from.  When building a program delete the subroutines that are not used to free up program space.

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


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


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


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

SYMBOL  Trigger         = PIN7                  ' SETUP = DN

SYMBOL  OUT6            = PIN6                  ' outputs
SYMBOL  OUT5            = PIN5
SYMBOL  OUT4            = PIN4
SYMBOL  OUT3            = PIN3
SYMBOL  OUT2            = PIN2
SYMBOL  OUT1            = PIN1
SYMBOL  OUT0            = PIN0


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

SYMBOL  TriggerTm       = 250                   ' trigger response time

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400


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

SYMBOL  timer           = W5


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

Power_Up:
  ' put code here that only happens at power-up/hard reset

Reset:
  PINS = %00000000                              ' all off
  DIRS = %01111111                              ' P6..P0 are outputs

  timer = 30                                    ' let PIR settle 30s
  GOSUB Wait_Secs


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

Main:
  GOSUB Wait_Trigger

  ' do somethig with outputs

  GOTO Reset


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

' hold program until trigger is active

Wait_Trigger:
  timer = 0

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < TriggerTm THEN Check_Trigger       ' check timer

  RETURN


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

' Put 0.1s units to wait in "timer" and then call this subroutine
' -- program stops (no outputs change) while this routine runs

Wait_Tics:
  IF timer = 0 THEN WT_Exit
    PAUSE 100
    timer = timer - 1
    GOTO Wait_Tics

WT_Exit:
  RETURN

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

' Put seconds to wait in "timer" and then call this subroutine
' -- program stops (no outputs change) while this routine runs

Wait_Secs:
  IF timer = 0 THEN WS_Exit
    PAUSE 1000
    timer = timer - 1
    GOTO Wait_Secs

WS_Exit:
  RETURN

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

' Put minutes to wait in "timer" and then call this subroutine
' -- program stops (no outputs change) while this routine runs

Wait_Mins:
  IF timer = 0 THEN WM_Exit
    PAUSE 60000
    timer = timer - 1
    GOTO Wait_Mins

WM_Exit:
  RETURN

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


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


Jon McPhalen
EFX-TEK Hollywood Office