November 23, 2024, 04:36:59 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.


Coffin Slider

Started by youngti, September 27, 2009, 02:58:51 PM

Previous topic - Next topic

JonnyMac

No, tix needs to be a byte, not a bit.  A byte can hold 0 to 255, a bit can only hold 0 to 1 (not useful here).  I would use B2 for tix.

The other thing to remember is that you need to set tix before calling (or falling into) that routine; if tix is zero the routine will end right away.  Here's an update of your program using Delay_Tix as a subroutine; note that tix is set to the delay value before the subroutine is called.  This is required every time because the subroutine consumes the value in tix.

' =========================================================================
'
'   File...... Sliding Coffin_V1.BS1
'   Purpose...
'   Author.... Tim Young
'   E-mail....
'   Started... 09-27-09
'   Updated... 10-05-09
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP, no ULN RC4
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  CAPAudio        = PIN5                  ' Cowlacious CAP200 (OUT5)
SYMBOL  LidOpen         = PIN4                  ' Limit Switch 1
SYMBOL  LidClosed       = PIN3                  ' Limit Switch 2


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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  relays          = B0
SYMBOL   Motor          =  BIT0
SYMBOL   Light          =  BIT1
SYMBOL   FOG            =  BIT2
SYMBOL   K4             =  BIT3

SYMBOL  tix             = B2

SYMBOL  timer           = W5


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

Reset:
 PINS = %00000000                              ' clear IOs
 DIRS = %00100000                              ' define output pins

 SEROUT Sio, Baud, ("!RC4", %00, "X")          ' clear RC-4 outputs

 tix = 150
 GOSUB Delay_Tix                               ' 15-second warm-up/reset


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

Main:
 timer = 0

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

 Motor = IsOn
 GOSUB Update_RC4

Let_Lid_Open:
 IF LidOpen = No THEN Let_Lid_Open

 Motor = IsOff
 Fog = IsOn
 GOSUB Update_RC4

Start_Audio:
 CAPAudio = IsOn
 PAUSE 250
 CAPAudio = IsOff

 Light = IsOn
 GOSUB Update_RC4

 tix = 40
 GOSUB Delay_Tix

 Motor = IsOn
 GOSUB Update_RC4

Let_Lid_Close:
 IF LidClosed = No THEN Let_Lid_Close

 GOTO Reset


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

Update_RC4:

 SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
 RETURN

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

' Load "tix" with 0.1-second units (10 units = 1 second)

Delay_Tix:
 IF tix = 0 THEN Delay_Tix_Exit
   PAUSE 100
   tix = tix - 1
   GOTO Delay_Tix

Delay_Tix_Exit:
 RETURN


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

youngti

Oh yeah, Bit verses byte, got confused.  Thank you

youngti

Thank you again.  Is it possible to call the subroutine in two different places?  If you are defining tix before you call the sub then you can conceivably have two different delays.  Say one for the fog to only turn on for 2 secs and then one for the program pause of 4 seconds.  I added the lines in to what I think would work.  I'm trying to limit the amount of fog while still having the 4 second pause for the show.

' =========================================================================
'
'   File...... Sliding Coffin_V1.BS1
'   Purpose...
'   Author.... Tim Young
'   E-mail....
'   Started... 09-27-09
'   Updated... 10-05-09
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP, no ULN RC4
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  CAPAudio        = PIN5                  ' Cowlacious CAP200 (OUT5)
SYMBOL  LidOpen         = PIN4                  ' Limit Switch 1
SYMBOL  LidClosed       = PIN3                  ' Limit Switch 2


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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  relays          = B0
SYMBOL   Motor          =  BIT0
SYMBOL   Light          =  BIT1
SYMBOL   FOG            =  BIT2
SYMBOL   K4             =  BIT3

SYMBOL  tix             = B2

SYMBOL  timer           = W5


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

Reset:
  PINS = %00000000                              ' clear IOs
  DIRS = %00100000                              ' define output pins

  SEROUT Sio, Baud, ("!RC4", %00, "X")          ' clear RC-4 outputs

  tix = 150
  GOSUB Delay_Tix                               ' 15-second warm-up/reset


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

Main:
  timer = 0

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

  Motor = IsOn
  GOSUB Update_RC4

Let_Lid_Open:
  IF LidOpen = No THEN Let_Lid_Open

  Motor = IsOff
  GOSUB Update_RC4

  Fog = IsOn
  GOSUB Update_RC4

  tix = 20
  GOSUB Delay_Tix

Start_Audio:
  CAPAudio = IsOn
  PAUSE 250
  CAPAudio = IsOff

  Light = IsOn
  GOSUB Update_RC4

  tix = 40
  GOSUB Delay_Tix

  Motor = IsOn
  GOSUB Update_RC4

Let_Lid_Close:
  IF LidClosed = No THEN Let_Lid_Close

  GOTO Reset


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

Update_RC4:

  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

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

' Load "tix" with 0.1-second units (10 units = 1 second)

Delay_Tix:
  IF tix = 0 THEN Delay_Tix_Exit
    PAUSE 100
    tix = tix - 1
    GOTO Delay_Tix

Delay_Tix_Exit:
  RETURN



livinlowe

Yeap, that should work!!
Shawn
Scaring someone with a prop you built -- priceless!

youngti

Cool  thank you, my daughter said "this is gona be the best halloween ever!"

JonnyMac

October 05, 2009, 12:45:53 PM #20 Last Edit: October 05, 2009, 12:50:11 PM by JonnyMac
The reason we use a subroutine is to reduce redundant code segments so, yes, you can call it from anywhere.  In this case, you must set the value of tix before the call, but otherwise, there are no restrictions.

Speaking of [possibly] redundant code, let me show you something -- this section:

  Motor = IsOff
 GOSUB Update_RC4

 Fog = IsOn
 GOSUB Update_RC4


... could be reduced to:

  Motor = IsOff
 Fog = IsOn
 GOSUB Update_RC4


The difference: in your version there is about a 30ms difference between the motor going off and the fog going on -- you'd never notice this, even if they were lights.  And... your code uses an extra subroutine call, which is limited (to 16) in the Prop-1.  In this program there is no harm but I encourage you to be as thrifty with your programming resources as Halloweeners tend to be with their $$$ --  ;D -- you may need those resources later and it's better to learn to be thrifty from the beginning.

Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Answering your question directly, you can get a four-second pause by pausing for four seconds, or by pausing for two seconds twice.  So, you want to structure your code:

Fog on
wait two seconds
Fog off
wait two seconds
Continue with show

The last line happens about four seconds after the fog started, and two seconds after it stopped.
Jon McPhalen
EFX-TEK Hollywood Office

youngti

Okay, I see that would save a little space.   I have 8 go-sub's so I've already used up half of the allowed.   I can see also that the way I've written it I actually have a 6 second delay.  2 for fog and 4 for the show.

Thank you so much.  As always you have been very helpfull.

livinlowe

Quote from: youngti on October 05, 2009, 01:08:28 PM
I have 8 go-sub's so I've already used up half of the allowed. 
You can have as many gosubs as you want, you can only have 16 nested gosubs. I think...pretty sure.  ???
Shawn
Scaring someone with a prop you built -- priceless!

BigRez

Quote
QuoteI have 8 go-sub's so I've already used up half of the allowed. 
You can have as many gosubs as you want, you can only have 16 nested gosubs. I think...pretty sure. 

Nope - that's a limit of 16 GOSUBs, nested or not.   (I'm running into that issue right now with 6 too many.  None are nested.)

youngti

Here is the final code.  Thanks to everybody who helped and it's working great.

' =========================================================================
'
'   File...... Sliding Coffin_V2.BS1
'   Purpose...
'   Author.... Tim Young
'   E-mail....
'   Started... 09-27-09
'   Updated... 10-11-09
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP, no ULN RC4
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  CAPAudio        = PIN5                  ' Cowlacious CAP200 (OUT5)
SYMBOL  LidOpen         = PIN4                  ' Limit Switch 1
SYMBOL  LidClosed       = PIN3                  ' Limit Switch 2


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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  relays          = B0
SYMBOL   Motor          =  BIT0
SYMBOL   Light          =  BIT1
SYMBOL   FOG            =  BIT2
SYMBOL   K4             =  BIT3

SYMBOL  tix             = B2

SYMBOL  timer           = W5


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

Reset:
  PINS = %00000000                              ' clear IOs
  DIRS = %00100000                              ' define output pins

  SEROUT Sio, Baud, ("!RC4", %00, "X")          ' clear RC-4 outputs

  tix = 150
  GOSUB Delay_Tix                               ' 15-second warm-up/reset


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

Main:
  timer = 0

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

  Fog = IsOn
  GOSUB Update_RC4

  tix = 20
  GOSUB Delay_Tix

  Fog = IsOff
  GOSUB Update_RC4

  Motor = IsOn
  GOSUB Update_RC4

Let_Lid_Open:
  IF LidOpen = No THEN Let_Lid_Open

  Motor = IsOff
  GOSUB Update_RC4

Start_Audio:
  CAPAudio = IsOn
  PAUSE 250
  CAPAudio = IsOff

  Light = IsOn
  GOSUB Update_RC4

  tix = 40
  GOSUB Delay_Tix

  Motor = IsOn
  GOSUB Update_RC4

Let_Lid_Close:
  IF LidClosed = No THEN Let_Lid_Close

  GOTO Reset


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

Update_RC4:

  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

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

' Load "tix" with 0.1-second units (10 units = 1 second)

Delay_Tix:
  IF tix = 0 THEN Delay_Tix_Exit
    PAUSE 100
    tix = tix - 1
    GOTO Delay_Tix

Delay_Tix_Exit:
  RETURN


BigRez

QuoteNope - that's a limit of 16 GOSUBs, nested or not.

Just ran across this in the documentation... You can have a total of 16 GOSUBs (prop-2/SX can have 255), but only four nested max. (version 2.2, Page 202.)

livinlowe

Thanks for digging through the documentation for the scoop. I know I've learned something, hopefully others will benefit from your work!
Shawn
Scaring someone with a prop you built -- priceless!