Number Ranges
Special_K
Posts: 162
Hello All,
I am looking for some help. I am working on a way to make the Boe-Bot slow down as it get various distances from a Ping))) sensor, and an IR Range finder. This is what the code looks like.
Is there a code/syntax for a range of values?
I am looking to have the Boe-Bot head forward at full speed (Given no sonar response) At a range between 25 and 16 centimeters half speed and at a range of 15 centimeters full stop at a range of 14 to 0 centimeters the Boe-Bot will backup to be 15 centimeters away so that turns can be made in a tight place.
·
forwardsearch:
DO
GOSUB Get_Sonar
IF cm<15 THEN
GOSUB backward
ELSEIF cm<25· THEN
GOSUB Forwardmed
ELSEIF cm>25 THEN
GOSUB forward
ENDIF
LOOP WHILE cm<>15
RETURN
I am looking for some help. I am working on a way to make the Boe-Bot slow down as it get various distances from a Ping))) sensor, and an IR Range finder. This is what the code looks like.
Is there a code/syntax for a range of values?
I am looking to have the Boe-Bot head forward at full speed (Given no sonar response) At a range between 25 and 16 centimeters half speed and at a range of 15 centimeters full stop at a range of 14 to 0 centimeters the Boe-Bot will backup to be 15 centimeters away so that turns can be made in a tight place.
·
forwardsearch:
DO
GOSUB Get_Sonar
IF cm<15 THEN
GOSUB backward
ELSEIF cm<25· THEN
GOSUB Forwardmed
ELSEIF cm>25 THEN
GOSUB forward
ENDIF
LOOP WHILE cm<>15
RETURN
Comments
Take a look at the SELECT ... CASE instruction which you will probably find will be very helpful here. SELECT ... CASE permits ranges of data values to be entered as targets. You can find out more about the SELECT ... CASE statement in the PBASIC Stamp Manual, or the PBASIC Stamp Help File.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
· SELECT cm
··· CASE < 15
····· GOSUB Backward
··· CASE 16 TO 25
····· GOSUB FowardMed
··· CASE > 25
····· GOSUB Forward
· ENDSELECT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Thanks!