EFX-TEK

TEK Talk => Prop-1 => Topic started by: youngti on September 27, 2009, 02:58:51 PM

Title: Coffin Slider
Post by: youngti on September 27, 2009, 02:58:51 PM
Well I was felling pretty good about myself.  Got this program working on the third try.  Except the Audio.  It is always the audio that gets me.  What I am doing is turning on a AC motor for the time specified, Turning on the light, fog and CAP200, then the motor turns back on and lights/fog/sound turn off.  Like i said everything works except for the audio.  I know the Audio code works because I am using the same thing in my ground breaker prop.  The CAP is hooked up the same way as this prop.  Below is the Code can provide is greatly e, I'm thinking that the position in the program is the problem but I can't find the issue.  Any help is greatly appreciated.

' =========================================================================
'
'   File...... Sliding Coffin_V1.BS1
'   Purpose...
'   Author.... Tim Young
'   E-mail....
'   Started... 09-27-09
'   Updated...
'
'   {$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)


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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

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

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

SYMBOL  timer           = W4

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

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

  SEROUT Sio, Baud, ("!RC4", %0000, "X")        ' clear RC-4 outputs
  PAUSE 15000                                   ' PIR warm-up, reset delay


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

  PAUSE 4555
  Motor = IsOff
  GOSUB Update_RC4

  Start_Audio:
  CAPAudio = IsOn
  PAUSE 250
  CAPAudio = IsOff

  Light = IsOn
  GOSUB Update_RC4

  FOG = IsOn
  GOSUB Update_RC4

  PAUSE 4000

  Motor = IsOn
  GOSUB Update_RC4

  PAUSE 4555
  Motor = IsOff
  GOSUB Update_RC4

  light = IsOff
  GOSUB Update_RC4

  FOG = IsOff
  GOSUB Update_RC4

  GOSUB Update_RC4



  timer = 0                                     ' restart timer

  GOTO Reset                                    ' clear everything,

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

Update_RC4:

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


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








Title: Re: Coffin Slider
Post by: JonnyMac on September 27, 2009, 05:28:46 PM
You need to make P5 (audio start pin) an output.  Change...

DIRS = %00000111

to...

DIRS = %00100000
Title: Re: Coffin Slider
Post by: youngti on September 27, 2009, 05:45:21 PM
Son of a.........  I had it backwards! 

Thank you so Much.
Title: Re: Coffin Slider
Post by: youngti on October 01, 2009, 01:11:22 PM
I am going to be adding two limit switches to control the motor instead of the Pause 4555.  using the pause I can't control the motor the way I want (having the coffin open and then close evenly each and every time).  The question I have is since I am already using the P7 and P6 jumpers I'm not sure how to connect these to the Prop 1 (they would probably need to be pulled down?).  These are mechanical switches and can be either NO or NC.

Also, I was planing to have the code read one switch (lid open), to stop the motor, pause for 4 seconds, then read the other switch(Lid closed) to start the motor again,  This would repeat each time the PIR is activated.  I'm trying to avoid having 4 switches.

Title: Re: Coffin Slider
Post by: JonnyMac on October 01, 2009, 01:29:58 PM
Use P3 and P4 with N.O. switches.  The ULN acts like a pull-down (which is why we have to clear it from P7 for SERIN/SEROUT to accessories) so you're set.  When dealing with motors limit switches are always the best way to go.  Let me know if you need a code assist once you get the limit switches connected.
Title: Re: Coffin Slider
Post by: youngti on October 01, 2009, 10:30:19 PM
Okay, I give.  I've tried to see if I can get this working but obiously I am not on the right track.   I feel like I've taken my simple working code and thrown a big wrench into it.  I would appreciate if you can show me where I am going wrong.

I have Switch one connected to P4, common to B-pin and NO to W-pin, Switch 2 is connecte to P3 the same way.  What I'm trying to get happen is This;

PIR is triggered
Motor runs until it hits Switch1 then stops.  Pauses for 4 seconds while Fog, Light, and sound run.
Then Fog, Light, and sound turn off.
Motor runs again until Switch 2 is activated and then everthing is reset to run agian.

' =========================================================================
'
'   File...... Sliding Coffin_V1.BS1
'   Purpose...
'   Author.... Tim Young
'   E-mail....
'   Started... 09-27-09
'   Updated...10-01-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  NO              = 1
SYMBOL  NC              = 0

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

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

SYMBOL  timer           = W4

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

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

  SEROUT Sio, Baud, ("!RC4", %0000, "X")        ' clear RC-4 outputs
  PAUSE 15000                                   ' PIR warm-up, reset delay


' -----[ 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
  Check_Lid_Open:    'Check if lid is fully opened
  IF LidOpen = NC THEN Check_Lid_Open:
  Motor = IsOff
  GOSUB Update_RC4


  FOG = IsOn
  GOSUB Update_RC4

  Start_Audio:
  CAPAudio = IsOn
  PAUSE 250
  CAPAudio = IsOff

  Light = IsOn
  GOSUB Update_RC4

    PAUSE 4000

  Motor = IsOn
  Check_Lid_Closed:    'Check if lid is fully closed
  IF LidClosed = NC THEN Check_Lid_Closed:
  Motor = IsOff
  GOSUB Update_RC4

  light = IsOff
  GOSUB Update_RC4

  FOG = IsOff
  GOSUB Update_RC4

  GOSUB Update_RC4



  timer = 0                                     ' restart timer

  GOTO Reset                                    ' clear everything,

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

Update_RC4:

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


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







Title: Re: Coffin Slider
Post by: livinlowe on October 02, 2009, 06:54:53 AM
Yougti-
I am pretty sure you have to go from the P4.R pin to P4.W as this will show as a high input when your switch closes. If you connect it to P4.B you wont ever show the switch closing. R=+5V, B=GND, W=Microprocessor input.

Hope this helps
Shawn
Title: Re: Coffin Slider
Post by: JonnyMac on October 02, 2009, 08:41:30 AM
Shaw is right: when using normally-open buttons or switches the connection is between the Px.W and Px.R terminals.  Here's what you're looking for -- not I removed some redundant code, and fixed some labels.

' =========================================================================
'
'   File...... Sliding Coffin_V1.BS1
'   Purpose...
'   Author.... Tim Young
'   E-mail....
'   Started... 09-27-09
'   Updated... 10-01-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  timer           = W5


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

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

  SEROUT Sio, Baud, ("!RC4", %00, "X")          ' clear RC-4 outputs
  PAUSE 15000                                   ' PIR warm-up, reset delay


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

  PAUSE 4000

  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


' -----[ User Data ]-------------------------------------------------------
Title: Re: Coffin Slider
Post by: youngti on October 02, 2009, 10:06:36 AM
Thank you I will try this tonight when I get home.  you guys are the best!
Title: Re: Coffin Slider
Post by: JonnyMac on October 02, 2009, 10:09:52 AM
You're getting very close to being able to do this all on your own time -- congrats!  Take the program I wrote, verify it, and then study it, asking yourself, "Why did that goofball do that?"  The answer will come and then will be stuck; you'll be flying through prop programming then.
Title: Re: Coffin Slider
Post by: youngti on October 03, 2009, 10:04:43 AM
Yeah, I see how you sis this.  thank you very much.  Once I moved the connections to W and R and uploaded this code it works!

I can see that I had a bunch of redundant lines in there.  Since the Prop1 dosen't have a timer function I'm thinking about adding a for next loop to cut down the fog from 4 seconds to 2.

Title: Re: Coffin Slider
Post by: JonnyMac on October 03, 2009, 07:17:50 PM
Remember that you can use any timing units you want.  For example, you could use a byte variable (Bx) which will give you [non-zero] values from 1 to 255 to create a 0.1 to 25.5 second delay -- something like this:

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

Delay_Tix_Exit:


The control variable -- and only one needed is called "tix" (short for ticks).  This routine gets a lot of use in programs I write as I can do longish delays at reasonable resolution using only a byte (memory is precious in the Prop-1).  Tix can also be randomized which is great for many apps.

Title: Re: Coffin Slider
Post by: livinlowe on October 03, 2009, 07:35:35 PM
You the man Youngti! Glad your prop is up and running!
Title: Re: Coffin Slider
Post by: youngti on October 05, 2009, 10:39:44 AM
So I would define a SYMBOL tix to location Bit4 then add this into the code.  But I would need to change tix = tix - 20 for 2 seconds.  Is this correct?

Fog = IsOn
  GOSUB Update_RC4

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

Delay_Tix_Exit:
Fog = IsOff
  GOSUB Update_RC4

Title: Re: Coffin Slider
Post by: livinlowe on October 05, 2009, 10:55:15 AM
No, not bit 4. You could do:


SYMBOL   tix = B1


You are assigning a byte variable to tix. Jon likes to keep B0 and B1 clear because you can access the individual bits in the byte, so B1 can be B2,B3, etc. Just not B8 or B9 (because of W5). I hope that makes sense  :)
Title: Re: Coffin Slider
Post by: JonnyMac on October 05, 2009, 11:01:01 AM
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 ]-------------------------------------------------------
Title: Re: Coffin Slider
Post by: youngti on October 05, 2009, 11:14:59 AM
Oh yeah, Bit verses byte, got confused.  Thank you
Title: Re: Coffin Slider
Post by: youngti on October 05, 2009, 11:26:19 AM
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


Title: Re: Coffin Slider
Post by: livinlowe on October 05, 2009, 11:30:56 AM
Yeap, that should work!!
Title: Re: Coffin Slider
Post by: youngti on October 05, 2009, 12:05:08 PM
Cool  thank you, my daughter said "this is gona be the best halloween ever!"
Title: Re: Coffin Slider
Post by: JonnyMac on October 05, 2009, 12:45:53 PM
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.

Title: Re: Coffin Slider
Post by: JonnyMac on October 05, 2009, 12:53:19 PM
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.
Title: Re: Coffin Slider
Post by: youngti on October 05, 2009, 01:08:28 PM
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.
Title: Re: Coffin Slider
Post by: livinlowe on October 05, 2009, 02:33:37 PM
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.  ???
Title: Re: Coffin Slider
Post by: BigRez on October 05, 2009, 03:47:42 PM
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.)
Title: Re: Coffin Slider
Post by: youngti on October 11, 2009, 02:40:05 PM
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
Title: Re: Coffin Slider
Post by: youngti on October 11, 2009, 04:32:05 PM
Here are the results.

http://www.youtube.com/watch?v=ja6JOIzkK3c

http://www.youtube.com/watch?v=ha0Bh_MUB3M
Title: Re: Coffin Slider
Post by: BigRez on November 20, 2009, 10:15:51 AM
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.)
Title: Re: Coffin Slider
Post by: livinlowe on November 21, 2009, 08:09:29 AM
Thanks for digging through the documentation for the scoop. I know I've learned something, hopefully others will benefit from your work!