« Basic Stamp circuits & Max patch | Main | Basic Stamp 2 code for communicating with MaxMSP »
September 25, 2003
Basic Stamp 2 code to switch lamp on and off
'{$STAMP BS2}
'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 0 'switch
output 1 'relay
'DECLARE VARIABLES
prevSwitchState var bit
'INITIALIZE VARIABLES
prevSwitchState = 0 'start with switch off
'MAIN LOOP
TOP:
if in0 <> prevSwitchState then ONOROFF 'branch if switch state changed
goto TOP
ONOROFF:
if in0 = 1 then LIGHTON 'if 1 then switch on
if in0 = 0 then LIGHTOFF 'if 0 then switch off
goto TOP
LIGHTON:
prevSwitchState = 1
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
Posted by at September 25, 2003 08:44 PM
Comments
Post a comment
Thanks for signing in, . Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)