Shop OBEX P1 Docs P2 Docs Learn Events
Number Ranges — Parallax Forums

Number Ranges

Special_KSpecial_K Posts: 162
edited 2006-02-27 05:21 in BASIC Stamp
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

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-26 11:58
    Special_K -

    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 -->
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-26 14:28
    Like this:

    · SELECT cm
    ··· CASE < 15
    ····· GOSUB Backward
    ··· CASE 16 TO 25
    ····· GOSUB FowardMed
    ··· CASE > 25
    ····· GOSUB Forward
    · ENDSELECT

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Special_KSpecial_K Posts: 162
    edited 2006-02-27 05:21
    That's the money!
    Thanks!
Sign In or Register to comment.