bs2 program help
I would like to know is there anyone could help me with the following program
This program is supposed to simulate a model elevator. Where when an input from pin3 is detected it counts the floors while output on pin9 and pin10 is supposed to turn on and off the motor as the shaft on the motor passes through a interupter that detected from pin3.
This program is supposed to simulate a model elevator. Where when an input from pin3 is detected it counts the floors while output on pin9 and pin10 is supposed to turn on and off the motor as the shaft on the motor passes through a interupter that detected from pin3.
' {$STAMP BS2}
' {$PBASIC 2.5}
cf VAR Byte
df VAR Byte
cf = 0
df = 0
Start:
DEBUG CLS
DEBUG DEC cf
DEBUG "Current Floor = ",cf ,CR
DEBUG "Enter Destination",CR
DEBUGIN NUM df
IF df > cf AND df <=9 THEN GOTO Up
IF df < cf AND df >=0 THEN GOTO Down
IF df = cf THEN GOTO Start
Up:
DEBUG "Elevator ascending", CR
DO
cf = cf+1
PAUSE(1000)
HIGH 10
LOW 9
DEBUG "Current Floor is ", DEC cf ,CR
LOOP UNTIL df = cf
PAUSE (500)
GOTO Start
Down:
DEBUG "Elevator Descending" ,CR
DO
cf = cf-1
PAUSE(1000)
IF NOT IN3 = 1 THEN EXIT
HIGH 9
LOW 10
DEBUG "Current Floor is ", DEC cf ,CR
LOOP UNTIL df = cf
PAUSE (500)
GOTO Start
END

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
sorry for the delay.
You should also limit the number os levels the elevator can reach...
Post Edited (Tibot) : 11/26/2005 8:00:07 PM GMT
cf = cf+1
PAUSE(1000)
HIGH 10
LOW 9
DEBUG "Current Floor is ", DEC cf ,CR
LOOP UNTIL df = cf
PAUSE (500)
GOTO Start
It looks like that part would just turn the motor on, cycle through the code, and head on back to start without actually looking at the elevator itself, leaving the elevator on.
I think it is the
IF NOT IN3=1 THEN EXIT
if not LOW on PIN N°3 then EXIT
similar to
if IN3=0 THEN EXIT
It means at this step, the Basic Stamp is looking at the PIN n°3 state.
If it is high, then EXIT the loop.
++