November 21, 2024, 11:39:11 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.


Code Help

Started by grofarms, February 13, 2009, 06:17:55 PM

Previous topic - Next topic

grofarms


I created a program for my prop which works great i just can't figure out how to write in a trigger on P6

Some help would be great!!!!!!!!!!!!1



'---------------------------------------------------------
'Project: Dog
'Author: Brian
'Farmerbrown726@gmail.com
'Started: 2/12/09
' {$STAMP BS1}
' {$PBASIC 1.0}

'=========================================================
'--------------Description--------------------------------
'Pop Out Dog Prop

'---------------------Definitions-------------------------
SYMBOL Out=0
SYMBOL Up=2
SYMBOL Lights=4
SYMBOL TRIGGER=6
'---------------------------------------------------------
MAIN:
HIGH Out         'Dog Out
PAUSE 2000       'Out Delay
LOW Out          'Dog In
PAUSE 1000       'In Delay

HIGH Out         'Dog Out
PAUSE 2000       'Out Delay
HIGH Up          'Dog Up
PAUSE 1500       'Up Delay
LOW Up           'Dog Down
LOW Out          'Dog In


HIGH Out         'Dog Out
PAUSE 2000       'Out Delay
LOW Out          'Dog In
PAUSE 1000       'In Delay

HIGH Out         'Dog Out
PAUSE 2000       'Out Delay
HIGH Up          'Dog Up
PAUSE 1500       'Up Delay
LOW Up           'Dog Down
LOW Out          'Dog In


HIGH Out         'Dog Out
PAUSE 2000       'Out Delay
HIGH Up          'Dog Up
PAUSE 1500       'Up Delay
LOW Up           'Dog Down
LOW Out          'Dog In

END


JonnyMac

February 13, 2009, 06:48:02 PM #1 Last Edit: February 13, 2009, 07:20:26 PM by JonnyMac
Here you go -- this matches your program but adds a trigger and is written in a more effective style.  That said... the dog does the same time every time it's triggered.  Would you like to add some randomness?

' =========================================================================
'
'   File......
'   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...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Lights          = PIN4
SYMBOL  DogUp           = PIN2
SYMBOL  DogOut          = PIN0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  timer           = B2


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00010101                              ' set outputs


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  DogOut = Yes
  PAUSE 2000
  DogOut = No
  PAUSE 1000

  DogOut = Yes
  PAUSE 2000
  DogUp = Yes
  PAUSE 1500
  DogUp = No
  DogOut = No

  DogOut = Yes
  PAUSE 2000
  DogOut = No
  PAUSE 1000

  DogOut = Yes
  PAUSE 2000
  DogUp = Yes
  PAUSE 1500
  DogUp = No
  DogOut = No

  DogOut = Yes
  PAUSE 2000
  DogUp = Yes
  PAUSE 1500
  DogUp = No
  DogOut = No

  GOTO Main


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


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


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Here's another version to try -- fair warning, though, it's a bit sophisticated.

This program generates a random value (in lottery) and copies that into a variable called show.  If there is a "1" in BIT0 (renamed routine) then it will play the code that causes the dog to come out and go up, otherwise it will just cause the dog to come out.  The timing in those routines is randomized a bit as well.  By using RANDOM it should make your prop a little more interesting as it won't every do the the same thing twice.

Let me know us know if this works -- and post video if you can.

' =========================================================================
'
'   File......
'   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...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Lights          = PIN4
SYMBOL  DogUp           = PIN2
SYMBOL  DogOut          = PIN0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  show            = B0
SYMBOL   routine        = BIT0

SYMBOL  timer           = B2
SYMBOL  plays           = B3

SYMBOL  delay           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00010101                              ' set outputs


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

  show = lottery                                ' randomize the show
  plays = 5                                     ' set # of routines

Play_Show:
  IF routine = 1 THEN Do_OutUp

Do_Out:
  GOSUB Dog_Out
  GOTO Next_Routine

Do_OutUp:
  GOSUB Dog_OutUp

Next_Routine:
  plays = plays - 1
  IF plays = 0 THEN Main                        ' if zero we're done
  show = show / 2                               ' get next show bit
  GOTO Play_Show


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

Dog_Out:
  DogOut = Yes
  RANDOM lottery
  delay = lottery // 1001 + 1500                ' 1500 to 2599
  PAUSE delay
  DogOut = No
  RANDOM lottery
  delay = lottery // 1001 + 500                 ' 500 to 1500
  PAUSE delay
  RETURN

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

Dog_OutUp:
  DogOut = Yes
  RANDOM lottery
  delay = lottery // 1001 + 1500                ' 1500 to 2599
  PAUSE delay
  DogUp = Yes
  RANDOM lottery
  delay = lottery // 1001 + 1000                ' 1000 to 2000
  PAUSE delay
  DogUp = No
  DogOut = No
  RETURN


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

grofarms

your first set of code is perfect accept for the part that it just keeps going it doesn't stop to be re triggered?

BigRez

I ran Jon's first program and using a prop-1 trainer, it works just fine.  That is, it goes through the sequence and then waits for another trigger before restarting.

What kind of trigger are you using? 

livinlowe

Make sure your setup jumper on your trigger input is on the down headers. If its on the up headers your prop will continually activate! ( I know, been there, done that!  :D  )
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

In addition to Shawn's note on the SETUP jumper, if you're using a PIR it may be continually firing and we'll have to add a delay between cycles.
Jon McPhalen
EFX-TEK Hollywood Office