November 21, 2024, 12:40:40 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.


normally closed magnet switch used to trigger prop2

Started by skipmcnoob@yahoo.com, September 08, 2011, 06:10:25 PM

Previous topic - Next topic

skipmcnoob@yahoo.com

Hello forum users! The code below is written to trigger a show when a hinged door closes. Now the problem I have been having is because the door is constantly closed, The show loops because it is constantly getting a signal from the trigger (a normally closed magnet trigger) that is on the door. Would anyone happen to know how I could modify this code to get the following?: Door is closed(no show), Door opens(no show), Door closes(show 1 time only, no loop) So UNTILL the next time the door is opened and then closed there is no show.

I have tried many different ways of writing this and cant seem to figure out how to get the above to happen. A friend of mine has asked the same question but I dont believe it was explained clearly.

' =========================================================================
'
'   File......
'   Purpose... Garner Holt Prod.
'   Author.... Chris Miller
'   E-mail.... skipmcnoob@yahoo.com
'   Created... 25 AUG 2011 - Generated by Vixen Prop-2 Sequencer Plug-in
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Triggered, table-drive sequencer capable of driving 14 control outputs.
' P14 is used as the trigger input, P15 is used for audio start when that
' option has been enabled.
'
' Note: When using the AP-8 you must replace ULN2803 with ULN2003 for
'       audio start on P15.
'
' Setup Jumpers:
'   -- P15 :: out
'   -- P14 :: DN for active-high; UP for active-low trigger
'   -- P13 :: out
'   -- P12 :: out
'
' Note: When use active-high input (PIR, etc) the P14 SETUP jumper should
'       be in the DN position and the input is between P14.R (red) and
'       P14.W (white).  When an active-low (open-collector, NPN) input is
'       used the ULN pin should be clipped and the P14 SETUP jumper is
'       in the UP position.  For active-low the connection is between
'       P14.B (black, ground) and P14.W (white, signal).


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


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

AudioStart      PIN     15                      ' SETUP = out
Trigger         PIN     14


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

T2400           CON     396
T9600           CON     84
T38K4           CON     6

Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open | T38K4            ' fast baud for accessories


IsActive        CON     1
IsNotActive     CON     0

IsOn            CON     1
IsOff           CON     0

EventDelay      CON     200


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

showBits        VAR     Word                    ' output + control bits
endOfShow       VAR     showBits.BIT15          ' 1 = stop when timer done

record          VAR     Word                    ' current sequence record
tix             VAR     Byte                    ' timing for record


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

Power_Up:
  PAUSE 2000                                    ' let everything start

Reset:
  OUTS = $0000                                  ' clear pins
  DIRS = $3FFF                                  ' P0..P13 are outputs

Audio_Reset:
  ' no audio device selected


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

Main:
  tix = 0

Check_Trigger:
  PAUSE 5
  tix = tix + 5
  IF Trigger = IsNotActive THEN Main            ' wait for trigger
  IF tix < 100 THEN Check_Trigger               ' debounce 100ms

Start_Audio:
  ' no audio device selected


Play_Show:
  READ (record * 3), Word showBits, tix         ' get outputs & timing
  OUTS = showBits & $3FFF                       ' update outputs

Timer:
  IF tix = 0 THEN Next_Step                     ' timer expired?
    PAUSE EventDelay                            '   no, time one "tic"
    tix = tix - 1                               '   decrement timer
    GOTO Timer                                  '   check again

Next_Step:
  INPUT AudioStart
  IF (endOfShow = IsOn) THEN Reset              ' done?
    record = record + 1                         '   no, point to next
    GOTO Play_Show                              '   and keep going


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


' -----[ EEPROM Data ]-----------------------------------------------------

Show_Data:
'
'
'
'             +-------------------- end of show Bit
'             |+------------------- trig
'             ||+------------------ Brightsign#1
'             |||+----------------- brightsign#2
'             ||||+---------------- overhead light
'             |||||+--------------- not active
'             ||||||+-------------- not active
'             |||||||+------------- not active
'             ||||||| +------------ LED 7
'             ||||||| |      +----- LED 0
'             ||||||| | 0-7  |
'             ||||||| |      |  +-- timing multiplier (1 to 255)
'             ||||||| |      |  |
  DATA  Word %0100000000000000, 1
  DATA  Word %0011000000000000, 1
  DATA  Word %0000000000000000, 34
  DATA  Word %0000000000000001, 1
  DATA  Word %0000000000000011, 1
  DATA  Word %0000000000000111, 1
  DATA  Word %0000000000001111, 1
  DATA  Word %0000100000011111, 1
  DATA  Word %0000100000111111, 1
  DATA  Word %0000100001111111, 3
  DATA  Word %0000100000000000, 36
  DATA  Word %0000000000000000, 119
  DATA  Word %1000000000000000, 1

JonnyMac

To do this you have to modify the trigger code.  What this means is that if you decide to change the sequencer portion, you should save your sequence to a scratch file, then copy-and-paste the sequence data (end of program listing) into this code.  This has two subroutines: one that waits for the door to be closed, another to wait for the door to be opened.

This works with standard, active-high wiring:
  -- SETUP jumper in DN position
  -- switch connected between P14.W and P14.R

' =========================================================================
'
'   File......
'   Purpose... Garner Holt Prod.
'   Author.... Chris Miller
'   E-mail.... skipmcnoob@yahoo.com
'   Created... 25 AUG 2011 - Generated by Vixen Prop-2 Sequencer Plug-in
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

AudioStart      PIN     15                      ' SETUP = out
Trigger         PIN     14


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

T2400           CON     396
T9600           CON     84
T38K4           CON     6

Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open | T38K4            ' fast baud for accessories


IsActive        CON     1
IsNotActive     CON     0

IsOn            CON     1
IsOff           CON     0

EventDelay      CON     200


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

showBits        VAR     Word                    ' output + control bits
endOfShow       VAR     showBits.BIT15          ' 1 = stop when timer done

record          VAR     Word                    ' current sequence record
tix             VAR     Byte                    ' timing for record


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

Power_Up:
  PAUSE 2000                                    ' let everything start

Reset:
  OUTS = $0000                                  ' clear pins
  DIRS = $3FFF                                  ' P0..P13 are outputs

Audio_Reset:
  ' no audio device selected


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

Main:
  GOSUB Wait_For_Closed                         ' force door to be closed
  GOSUB Wait_For_Opened                         ' wait for door to open
  GOSUB WAIT_For_Closed                         ' and then close


Start_Audio:
  ' no audio device selected


Play_Show:
  READ (record * 3), Word showBits, tix         ' get outputs & timing
  OUTS = showBits & $3FFF                       ' update outputs

Timer:
  IF tix = 0 THEN Next_Step                     ' timer expired?
    PAUSE EventDelay                            '   no, time one "tic"
    tix = tix - 1                               '   decrement timer
    GOTO Timer                                  '   check again

Next_Step:
  INPUT AudioStart
  IF (endOfShow = IsOn) THEN Reset              ' done?
    record = record + 1                         '   no, point to next
    GOTO Play_Show                              '   and keep going


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

' Input pin (P14) is 1 when door is closed


Wait_For_Closed:
  tix = 0

WFC_Loop:
  PAUSE 5
  IF Trigger = IsNotActive THEN Wait_For_Closed
  tix = tix + 5
  IF tix < 100 THEN WFC_Loop

WFC_Exit:
  RETURN

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

' Input pin (P14) is 0 when door switch opened

Wait_For_Opened:
  tix = 0

WFO_Loop:
  PAUSE 5
  IF Trigger = IsActive THEN Wait_For_Opened
  tix = tix + 5
  IF tix < 100 THEN WFO_Loop

WFO_Exit:
  RETURN


' -----[ EEPROM Data ]-----------------------------------------------------

Show_Data:
'
'
'
'             +-------------------- end of show Bit
'             |+------------------- trig
'             ||+------------------ Brightsign#1
'             |||+----------------- brightsign#2
'             ||||+---------------- overhead light
'             |||||+--------------- not active
'             ||||||+-------------- not active
'             |||||||+------------- not active
'             ||||||| +------------ LED 7
'             ||||||| |      +----- LED 0
'             ||||||| | 0-7  |
'             ||||||| |      |  +-- timing multiplier (1 to 255)
'             ||||||| |      |  |
  DATA  Word %0100000000000000, 1
  DATA  Word %0011000000000000, 1
  DATA  Word %0000000000000000, 34
  DATA  Word %0000000000000001, 1
  DATA  Word %0000000000000011, 1
  DATA  Word %0000000000000111, 1
  DATA  Word %0000000000001111, 1
  DATA  Word %0000100000011111, 1
  DATA  Word %0000100000111111, 1
  DATA  Word %0000100001111111, 3
  DATA  Word %0000100000000000, 36
  DATA  Word %0000000000000000, 119
  DATA  Word %1000000000000000, 1
Jon McPhalen
EFX-TEK Hollywood Office

skipmcnoob@yahoo.com

Thank You! I really appreciate you taking the time to correct my code!
I think this will do it... :D

skipmcnoob@yahoo.com

Hello All,
I have a code for a short show and there seems to be an error (made by myself) in the program somewhere, that I cant seem to find. If anyone has any suggestions of as to why this is not working it would be a BIG help ;D

' =========================================================================
'
'   File......
'   Purpose... Garner Holt Prod.
'   Author.... Chris Miller
'   E-mail.... skipmcnoob@yahoo.com
'   Created... 25 AUG 2011 - Generated by Vixen Prop-2 Sequencer Plug-in
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

AudioStart      PIN     15                      ' SETUP = out
Trigger         PIN     14


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

T2400           CON     396
T9600           CON     84
T38K4           CON     6

Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open | T38K4            ' fast baud for accessories


IsActive        CON     1
IsNotActive     CON     0

IsOn            CON     1
IsOff           CON     0

EventDelay      CON     200


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

showBits        VAR     Word                    ' output + control bits
endOfShow       VAR     showBits.BIT15          ' 1 = stop when timer done

record          VAR     Word                    ' current sequence record
tix             VAR     Byte                    ' timing for record


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

Power_Up:
  PAUSE 2000                                    ' let everything start

Reset:
  OUTS = $0000                                  ' clear pins
  DIRS = $3FFF                                  ' P0..P13 are outputs

Audio_Reset:
  ' no audio device selected


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

Main:
  GOSUB Wait_For_Closed                         ' force door to be closed
  GOSUB Wait_For_Opened                         ' wait for door to open
  GOSUB WAIT_For_Closed                         ' and then close


Start_Audio:
  ' no audio device selected


Play_Show:
  READ (record * 3), Word showBits, tix         ' get outputs & timing
  OUTS = showBits & $3FFF                       ' update outputs

Timer:
  IF tix = 0 THEN Next_Step                     ' timer expired?
    PAUSE EventDelay                            '   no, time one "tic"
    tix = tix - 1                               '   decrement timer
    GOTO Timer                                  '   check again

Next_Step:
  INPUT AudioStart
  IF (endOfShow = IsOn) THEN Reset              ' done?
    record = record + 1                         '   no, point to next
    GOTO Play_Show                              '   and keep going


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

' Input pin (P14) is 1 when door is closed


Wait_For_Closed:
  tix = 0

WFC_Loop:
  PAUSE 5
  IF Trigger = IsNotActive THEN Wait_For_Closed
  tix = tix + 5
  IF tix < 100 THEN WFC_Loop

WFC_Exit:
  RETURN

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

' Input pin (P14) is 0 when door switch opened

Wait_For_Opened:
  tix = 0

WFO_Loop:
  PAUSE 5
  IF Trigger = IsActive THEN Wait_For_Opened
  tix = tix + 5
  IF tix < 100 THEN WFO_Loop

WFO_Exit:
  RETURN


' -----[ EEPROM Data ]-----------------------------------------------------

Show_Data:
'
'
'
'             +-------------------- end of show Bit
'             |+------------------- trig
'             ||+------------------ Brightsign#1
'             |||+----------------- brightsign#2
'             ||||+---------------- overhead light
'             |||||+--------------- not active
'             ||||||+-------------- not active
'             |||||||+------------- not active
'             ||||||| +------------ LED 7
'             ||||||| |      +----- LED 0
'             ||||||| | 0-7  |
'             ||||||| |      |  +-- timing multiplier (1 to 255)
'             ||||||| |      |  |
  DATA  Word %0100000000000000, 1
  DATA  Word %0011000000000000, 1
  DATA  Word %0000000000000000, 34
  DATA  Word %0000000000000001, 1
  DATA  Word %0000000000000011, 1
  DATA  Word %0000000000000111, 1
  DATA  Word %0000000000001111, 1
  DATA  Word %0000100000011111, 1
  DATA  Word %0000100000111111, 1
  DATA  Word %0000100001111111, 3
  DATA  Word %0000100000000000, 36
  DATA  Word %0000000000000000, 119
  DATA  Word %1000000000000000, 1

bsnut

What you need to is, tell us what it isn't doing.

The best troubleshooter is inserting the DEBUG Command with a statement like this after each of labels

Wait_For_Closed:
DEBUG CR , "Wait for closed works"

Doing this will help you find your problems in your code.
William Stefan
The Basic Stamp Nut

JonnyMac

William's idea of adding DEBUG statements is a good one, and along the way I found that the record variable was not getting reset to 0 when you start a second show.  All variables are cleared to zero on power-up which is why that was working for you.

Give this version a go; it should work and will tell you what it's doing along the way.

' =========================================================================
'
'   File......
'   Purpose... Garner Holt Prod.
'   Author.... Chris Miller
'   E-mail.... skipmcnoob@yahoo.com
'   Created... 25 AUG 2011 - Generated by Vixen Prop-2 Sequencer Plug-in
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

AudioStart      PIN     15                      ' SETUP = out
Trigger         PIN     14


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

T2400           CON     396
T9600           CON     84
T38K4           CON     6

Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open | T38K4            ' fast baud for accessories


IsActive        CON     1
IsNotActive     CON     0

IsOn            CON     1
IsOff           CON     0

EventDelay      CON     200


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

showBits        VAR     Word                    ' output + control bits
endOfShow       VAR     showBits.BIT15          ' 1 = stop when timer done

record          VAR     Word                    ' current sequence record
tix             VAR     Byte                    ' timing for record


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

Power_Up:
  PAUSE 2000                                    ' let everything start

Reset:
  OUTS = $0000                                  ' clear pins
  DIRS = $3FFF                                  ' P0..P13 are outputs
  DEBUG CLS, "Program reset.", CR

Audio_Reset:
  ' no audio device selected


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

Main:
  GOSUB Wait_For_Closed                         ' force door to be closed
  GOSUB Wait_For_Opened                         ' wait for door to open
  GOSUB WAIT_For_Closed                         ' and then close


Start_Audio:
  ' no audio device selected

  DEBUG "Starting sequence.", CR
  record = 0

Play_Show:
  READ (record * 3), Word showBits, tix         ' get outputs & timing
  OUTS = showBits & $3FFF                       ' update outputs

Timer:
  IF tix = 0 THEN Next_Step                     ' timer expired?
    PAUSE EventDelay                            '   no, time one "tic"
    tix = tix - 1                               '   decrement timer
    GOTO Timer                                  '   check again

Next_Step:
  INPUT AudioStart
  IF (endOfShow = IsOn) THEN Reset              ' done?
    record = record + 1                         '   no, point to next
    GOTO Play_Show                              '   and keep going


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

' Input pin (P14) is 1 when door is closed


Wait_For_Closed:
  tix = 0

WFC_Loop:
  PAUSE 5
  IF Trigger = IsNotActive THEN Wait_For_Closed
  tix = tix + 5
  IF tix < 100 THEN WFC_Loop

WFC_Exit:
  DEBUG "Door closed.", CR
  RETURN

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

' Input pin (P14) is 0 when door switch opened

Wait_For_Opened:
  tix = 0

WFO_Loop:
  PAUSE 5
  IF Trigger = IsActive THEN Wait_For_Opened
  tix = tix + 5
  IF tix < 100 THEN WFO_Loop

WFO_Exit:
  DEBUG "Door opened.", CR
  RETURN


' -----[ EEPROM Data ]-----------------------------------------------------

Show_Data:
'
'
'
'             +-------------------- end of show Bit
'             |+------------------- trig
'             ||+------------------ Brightsign#1
'             |||+----------------- brightsign#2
'             ||||+---------------- overhead light
'             |||||+--------------- not active
'             ||||||+-------------- not active
'             |||||||+------------- not active
'             ||||||| +------------ LED 7
'             ||||||| |      +----- LED 0
'             ||||||| | 0-7  |
'             ||||||| |      |  +-- timing multiplier (1 to 255)
'             ||||||| |      |  |
  DATA  Word %0100000000000000, 1
  DATA  Word %0011000000000000, 1
  DATA  Word %0000000000000000, 34
  DATA  Word %0000000000000001, 1
  DATA  Word %0000000000000011, 1
  DATA  Word %0000000000000111, 1
  DATA  Word %0000000000001111, 1
  DATA  Word %0000100000011111, 1
  DATA  Word %0000100000111111, 1
  DATA  Word %0000100001111111, 3
  DATA  Word %0000100000000000, 36
  DATA  Word %0000000000000000, 119
  DATA  Word %1000000000000000, 1
Jon McPhalen
EFX-TEK Hollywood Office

skipmcnoob@yahoo.com

ohh okay i see. Thank you
Ill give this a go and let you know how it turns out... ;D

skipmcnoob@yahoo.com

Thank you for all your help!
Got everything working properly.
I really appreciate it!

JonnyMac

Excellent news! Future projects, I dare say, will probably go more smoothly.
Jon McPhalen
EFX-TEK Hollywood Office

skipmcnoob@yahoo.com

Well I think this entire experience has helped make me a better prop programmer. :D
So yes I believe that future projects will be a bit easier...
Thanks again everyone!