5: BASIC Stamp Command Reference – LOOKDOWN
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 181
below shows some sample, non-contiguous inputs and the corresponding
outputs the BASIC Stamp needs to respond with:
Each of these values received
(inputs):
Needs to result in each of these
values sent (outputs):
5
16
14
17
1
18
43
24
26
10
22
12
30
11
So, if we receive the number 5, we need to output 16. If we received 43,
we need to output 24, and so on. These numbers are not contiguous and
they don't appear to be derived from any simple algorithm. We can solve
this problem with two lines of code, as follows:
LOOKDOWN Value, [5, 14, 1, 43, 26, 22, 30], Value
LOOKUP Value, [16, 17, 18, 24, 10, 12, 11], Value
Assuming our received number is in Value, the first line (LOOKDOWN)
will find the value in the list and store the index of the location that
matches back into Value. (This step "maps" the non-contiguous numbers:
5, 14, 1, etc, to a contiguous set of numbers: 0, 1, 2, etc). The second line
(LOOKUP) takes our new Value, finds the number at that location and
stores it back into Value. If the received value was 14, LOOKDOWN stores
1 into Value and LOOKUP looks at the value at location 1 and stores 17 in
Value. The number 43 gets mapped to 3, 3 gets mapped to 24, and so on.
This is a quick and easy fix for a potentially messy problem!
Table 5.37: Non-Contiguous
Number Example
Содержание BASIC Stamp 2e
Страница 1: ...BASIC Stamp Programming Manual Version 2 0c...
Страница 30: ...Introduction to the BASIC Stamps Page 28 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 90: ...BUTTON BASIC Stamp Command Reference Page 88 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 118: ...END BASIC Stamp Command Reference Page 116 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 128: ...FREQOUT BASIC Stamp Command Reference Page 126 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 196: ...NAP BASIC Stamp Command Reference Page 194 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 206: ...OWIN BASIC Stamp Command Reference Page 204 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 214: ...OWOUT BASIC Stamp Command Reference Page 212 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 216: ...PAUSE BASIC Stamp Command Reference Page 214 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 226: ...POLLMODE BASIC Stamp Command Reference Page 224 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 232: ...POLLOUT BASIC Stamp Command Reference Page 230 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 236: ...POLLRUN BASIC Stamp Command Reference Page 234 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 240: ...POLLWAIT BASIC Stamp Command Reference Page 238 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 262: ...RCTIME BASIC Stamp Command Reference Page 260 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 274: ...RUN BASIC Stamp Command Reference Page 272 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 310: ...SEROUT BASIC Stamp Command Reference Page 308 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 324: ...STOP BASIC Stamp Command Reference Page 322 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...