I need help with program code
I have a Halloween·prop that is a witch riding a broom.
I have a spot light that will come on and light her up. Under her dress is a fogger which puts fog out the end of the broom. Her head moves up & down, And back & forth. Her eyes are yellow LEDs that fade· off & on. Her arm goes up & down waving a wand which has an LED cluster on the end and they change colors. (Her head has A Scary Terry audio board that run the mouth and sound)
I'm using a prop-2 controller board and an RC-4 relay board for the relays to run the motors & lights. My problem is somewhere in the program code. I download the program but when activated the RC-4 card is not responding.
I'm running a ser cable from pin 15 to the ser pin on the RC-4 board.
This is what I want the prop to do:
pin 14, trigger sensor·to activate prop
pin·0, runs audio card for 60sec
then pin 15 runs relay board:
····· soptlight relay = K1 on for 60sec
····· motor relays = K2 on for 60sec
····· fogger relay = K3·on 60sec while cycling 10 times (4sec on & 2 sec off)
program will stay off for 60sec before resetting
Here's the program so far. If any one can see where or whats wrong Please let me know. Thanks
'···{$STAMP BS2}
'· ·{$PBASIC 2.5}
'
' =========================================================================
'·
[noparse][[/noparse] I/O Definitions ]
Sio· · · · · · ·PIN· · ·15· · · · · · · · · · · ' No ULN, SETUP = Out
Trigger· · · · ·PIN· · ·14· · · · · · · · · · · ' SETUP = DN
Audio· · · · · ·PIN· · · 0· · · · · · · · · · · ' use OUT0 to ST audio bd
'
[noparse][[/noparse] Constants ]
IsOn· · · · · · CON· · ·1
IsOff· · · · · ·CON· · ·0
#SELECT $STAMP
· #CASE BS2, BS2E, BS2PE
· · T2400· · · ·CON· · ·396
· · T38K4· · · ·CON· · ·6
· #CASE BS2SX, BS2P
· · T2400· · · ·CON· · ·1021
· · T38K4· · · ·CON· · ·45
· #CASE BS2PX
· · T2400· · · ·CON· · ·1646
· · T38K4· · · ·CON· · ·84
#ENDSELECT
SevenBit· · · · CON· · ·$2000
Inverted· · · · CON· · ·$4000
Open· · · · · · CON· · ·$8000
Baud· · · · · · CON· · ·Open + T38K4· · · · · · ' B/R jumper is installed
'
[noparse][[/noparse] Variables ]
relays· · · · · VAR· · ·Byte
·spotLight· · · VAR· · ·relays.BIT0· · · · · · ·' K1
·motor· · · · · VAR· · ·relays.BIT1· · · · · · ·' K2
·fogger· · · · ·VAR· · ·relays.BIT2· · · · · · ·' K3
timer· · · · · ·VAR· · ·Byte· · · · · · · · · · ' for trigger debouncing
cycles· · · · · VAR· · ·Byte
'
[noparse][[/noparse] Initialization ]
Reset:
· OUTS = %00000000· · · · · · · · · · · · · · · ' clear pins
· DIRS = %00000001· · · · · · · · · · · · · · · ' make P0 an output
· relays = %0000
· SEROUT Sio, Baud, [noparse][[/noparse]"!!!!!!RC4", %00, "X"]· · ·' clear RC-4
· PAUSE 60000
'
[noparse][[/noparse] Program Code ]
Main:
· timer = 0· · · · · · · · · · · · · · · · · · ·' reset timer
· DO WHILE (timer < 100)· · · · · · · · · · · · ' wait for valid trigger
· · PAUSE 5· · · · · · · · · · · · · · · · · · ·' loop pad
· · timer = timer + 5 * Trigger· · · · · · · · ·' update timer value
· LOOP
· Audio = IsOn
· PAUSE 25
· Audio = IsOff
· spotlight = IsOn
· motor = IsOn
· GOSUB Update_RC4
· ' fogger cycling creates 60-second delay
· FOR cycles = 1 TO 10
· · fogger = IsOn
· · PAUSE 4000
· · GOSUB Update_RC4
· · fogger = IsOff
· · PAUSE 2000
· · GOSUB Update_RC4
· NEXT
· GOTO Reset· · · · · · · · · · · · · · · · · · ' reset everything
'
[noparse][[/noparse] Subroutines ]
' Assumes RC-4 A0 and A1 jumpers are removed
Update_RC4:
· SEROUT Sio, Baud, [noparse][[/noparse]"!RC4", %00, "S", relays]
· RETURN
I have a spot light that will come on and light her up. Under her dress is a fogger which puts fog out the end of the broom. Her head moves up & down, And back & forth. Her eyes are yellow LEDs that fade· off & on. Her arm goes up & down waving a wand which has an LED cluster on the end and they change colors. (Her head has A Scary Terry audio board that run the mouth and sound)
I'm using a prop-2 controller board and an RC-4 relay board for the relays to run the motors & lights. My problem is somewhere in the program code. I download the program but when activated the RC-4 card is not responding.
I'm running a ser cable from pin 15 to the ser pin on the RC-4 board.
This is what I want the prop to do:

pin·0, runs audio card for 60sec
then pin 15 runs relay board:
····· soptlight relay = K1 on for 60sec
····· motor relays = K2 on for 60sec
····· fogger relay = K3·on 60sec while cycling 10 times (4sec on & 2 sec off)
program will stay off for 60sec before resetting
Here's the program so far. If any one can see where or whats wrong Please let me know. Thanks
'···{$STAMP BS2}
'· ·{$PBASIC 2.5}
'
' =========================================================================
'·
[noparse][[/noparse] I/O Definitions ]
Sio· · · · · · ·PIN· · ·15· · · · · · · · · · · ' No ULN, SETUP = Out
Trigger· · · · ·PIN· · ·14· · · · · · · · · · · ' SETUP = DN
Audio· · · · · ·PIN· · · 0· · · · · · · · · · · ' use OUT0 to ST audio bd
'
[noparse][[/noparse] Constants ]
IsOn· · · · · · CON· · ·1
IsOff· · · · · ·CON· · ·0
#SELECT $STAMP
· #CASE BS2, BS2E, BS2PE
· · T2400· · · ·CON· · ·396
· · T38K4· · · ·CON· · ·6
· #CASE BS2SX, BS2P
· · T2400· · · ·CON· · ·1021
· · T38K4· · · ·CON· · ·45
· #CASE BS2PX
· · T2400· · · ·CON· · ·1646
· · T38K4· · · ·CON· · ·84
#ENDSELECT
SevenBit· · · · CON· · ·$2000
Inverted· · · · CON· · ·$4000
Open· · · · · · CON· · ·$8000
Baud· · · · · · CON· · ·Open + T38K4· · · · · · ' B/R jumper is installed
'
[noparse][[/noparse] Variables ]
relays· · · · · VAR· · ·Byte
·spotLight· · · VAR· · ·relays.BIT0· · · · · · ·' K1
·motor· · · · · VAR· · ·relays.BIT1· · · · · · ·' K2
·fogger· · · · ·VAR· · ·relays.BIT2· · · · · · ·' K3
timer· · · · · ·VAR· · ·Byte· · · · · · · · · · ' for trigger debouncing
cycles· · · · · VAR· · ·Byte
'
[noparse][[/noparse] Initialization ]
Reset:
· OUTS = %00000000· · · · · · · · · · · · · · · ' clear pins
· DIRS = %00000001· · · · · · · · · · · · · · · ' make P0 an output
· relays = %0000
· SEROUT Sio, Baud, [noparse][[/noparse]"!!!!!!RC4", %00, "X"]· · ·' clear RC-4
· PAUSE 60000
'
[noparse][[/noparse] Program Code ]
Main:
· timer = 0· · · · · · · · · · · · · · · · · · ·' reset timer
· DO WHILE (timer < 100)· · · · · · · · · · · · ' wait for valid trigger
· · PAUSE 5· · · · · · · · · · · · · · · · · · ·' loop pad
· · timer = timer + 5 * Trigger· · · · · · · · ·' update timer value
· LOOP
· Audio = IsOn
· PAUSE 25
· Audio = IsOff
· spotlight = IsOn
· motor = IsOn
· GOSUB Update_RC4
· ' fogger cycling creates 60-second delay
· FOR cycles = 1 TO 10
· · fogger = IsOn
· · PAUSE 4000
· · GOSUB Update_RC4
· · fogger = IsOff
· · PAUSE 2000
· · GOSUB Update_RC4
· NEXT
· GOTO Reset· · · · · · · · · · · · · · · · · · ' reset everything
'
[noparse][[/noparse] Subroutines ]
' Assumes RC-4 A0 and A1 jumpers are removed
Update_RC4:
· SEROUT Sio, Baud, [noparse][[/noparse]"!RC4", %00, "S", relays]
· RETURN
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen