LOOKDOWN - BASIC Stamp Command Reference
Page 180
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
ComparisonOp Symbol
Description
=
Find the first value Target is equal to
<>
Find the first value Target is not equal to
>
Find the first value Target is greater than
<
Find the first value Target is less than
>=
Find the first value Target is greater than or equal to
<=
Find the first value Target is less than or equal to
A common application for LOOKDOWN is to use it in conjunction with
the BRANCH command to create selective jumps based on a simple
variable input:
Cmd VAR BYTE
Cmd = "M"
LOOKDOWN Cmd, ["SLMH"], Cmd
BRANCH Cmd, [_Stop, _Low, _Medium, _High]
DEBUG "Command not in list"
END
_Stop: DEBUG "stop"
END
_Low: DEBUG "low"
END
_Medium: DEBUG "medium"
END
_High: DEBUG "high"
END
In this example, Cmd contains “M” (ASCII 77). LOOKDOWN finds that
this is item 2 of a list of one-character commands and stores 2 into Cmd.
BRANCH then goes to item 2 of its list, which is the program label
“_Medium” at which point DEBUG prints “medium” on the PC screen.
This is a powerful method for interpreting user input, and a lot neater
than the alternative IF...THEN instructions.
Another great use of LOOKDOWN is in combination with LOOKUP to
"map" non-contiguous sets of numbers together. For example, you may
have an application where certain numbers are received by the BASIC
Stamp and, in response, the BASIC Stamp needs to send a specific set of
numbers. This may be easy to code if the numbers are contiguous, or
follow some know algebraic equations… but what if they don't? The table
U
SING
LOOKDOWN
WITH
BRANCH
TO JUMP BASED ON VALUES
.
NOTE: For BS1's, change line 1 to:
SYMBOL Cmd = B0
And replace the [ and ] symbols
with ( and ) in lines 4 and 5.
U
SING
LOOKDOWN
WITH
LOOKUP
TO
"
MAP
"
NON
-
CONTIGUOUS SETS OF
NUMBERS
.
Table 5.36: LOOKDOWN
Comparison Operators.
Summary of Contents for BASIC Stamp 1
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...