March 28, 2024, 10:51:52 AM

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

youngti

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 ]-------------------------------------------------------









JonnyMac

You need to make P5 (audio start pin) an output.  Change...

DIRS = %00000111

to...

DIRS = %00100000
Jon McPhalen
EFX-TEK Hollywood Office

youngti

Son of a.........  I had it backwards! 

Thank you so Much.

youngti

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.


JonnyMac

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.
Jon McPhalen
EFX-TEK Hollywood Office

youngti

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 ]-------------------------------------------------------








livinlowe

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
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

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 ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

youngti

Thank you I will try this tonight when I get home.  you guys are the best!

JonnyMac

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.
Jon McPhalen
EFX-TEK Hollywood Office

youngti

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.


JonnyMac

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.

Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

You the man Youngti! Glad your prop is up and running!
Shawn
Scaring someone with a prop you built -- priceless!

youngti

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


livinlowe

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  :)
Shawn
Scaring someone with a prop you built -- priceless!