input program problems
i need one input to start a light or relay output energized
i need both inputs to shut it off or only input 8 to shut it off
the light comes on and goes off only when you press both switches simultaneously
i know this processor is capable but it will not shut off the light with only in8 = 1
i have attached the program any help could be useful
also if anyone knows where to get some really good 5v relays for this please let me know
except for radio shacks reed style i dont like them personally
'{$STAMP BS2}
' {$PBASIC 2.0}
'BASIC STAMP 2 FIRST PROJECT V1 - SWITCH LIGHT ON & OFF
'WHAT SHOULD HAPPEN:
'When the switch is closed, the light goes on.
'DECLARE INS & OUTS
INPUT 3 'switch
INPUT 8 'switch
OUTPUT 1 'relay
'DECLARE VARIABLES
prevSwitchState VAR Bit
'INITIALIZE VARIABLES
prevSwitchState = 0 'start with switch off
'MAIN LOOP
TOP:
IF IN3 <> prevSwitchState THEN ONOROFF 'branch if switch state changed
GOTO TOP
onoroff:
IF IN3 = 1 AND IN8 = 0 THEN LIGHTON 'if 1 then switch on
IF IN3 = 0 AND IN8 = 1 THEN lightoff 'if 1 then switch off
IF IN8 = 1 THEN lightoff 'if 1 then switch off
GOTO top
LIGHTON:
prevswitchstate = 0
HIGH 1 'turn on light
DEBUG "light should be ON...",CR
GOTO TOP
LIGHTOFF:
prevSwitchState = 0
LOW 1 'turn off light
DEBUG "light should be OFF...",CR
GOTO TOP
i need both inputs to shut it off or only input 8 to shut it off
the light comes on and goes off only when you press both switches simultaneously
i know this processor is capable but it will not shut off the light with only in8 = 1
i have attached the program any help could be useful
also if anyone knows where to get some really good 5v relays for this please let me know
except for radio shacks reed style i dont like them personally
'{$STAMP BS2}
' {$PBASIC 2.0}
'BASIC STAMP 2 FIRST PROJECT V1 - SWITCH LIGHT ON & OFF
'WHAT SHOULD HAPPEN:
'When the switch is closed, the light goes on.
'DECLARE INS & OUTS
INPUT 3 'switch
INPUT 8 'switch
OUTPUT 1 'relay
'DECLARE VARIABLES
prevSwitchState VAR Bit
'INITIALIZE VARIABLES
prevSwitchState = 0 'start with switch off
'MAIN LOOP
TOP:
IF IN3 <> prevSwitchState THEN ONOROFF 'branch if switch state changed
GOTO TOP
onoroff:
IF IN3 = 1 AND IN8 = 0 THEN LIGHTON 'if 1 then switch on
IF IN3 = 0 AND IN8 = 1 THEN lightoff 'if 1 then switch off
IF IN8 = 1 THEN lightoff 'if 1 then switch off
GOTO top
LIGHTON:
prevswitchstate = 0
HIGH 1 'turn on light
DEBUG "light should be ON...",CR
GOTO TOP
LIGHTOFF:
prevSwitchState = 0
LOW 1 'turn off light
DEBUG "light should be OFF...",CR
GOTO TOP
Comments
LOW 1
GOSUB Lightoff
main:
IF IN3=1 THEN GOSUB Lighton
IF IN8=1 THEN GOSUB Lightoff
GOTO main
Lighton:
HIGH 1
DEBUG "Light is on",CR
RETURN
Lightoff:
LOW 1
DEBUG "Light is off",CR
RETURN
Jeff T.