LOOKDOWN - BASIC Stamp Command Reference
Page 182
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
Demo Program (LOOKDOWN.bas)
' This program uses LOOKDOWN followed by LOOKUP to map the numbers:
' 0, 10, 50, 64, 71 and 98 to 35, 40, 58, 62, 79, and 83, respectively. All other
' numbers are mapped to 255.
'{$STAMP BS1} 'STAMP directive (specifies a BS1)
SYMBOL I = W0 ' Holds current number.
SYMBOL Result = W1 ' Holds mapped result.
FOR I = 0 TO 100
Result = 255 ' If no match in list, must be 0.
LOOKDOWN I, (0, 10, 50, 64, 71, 98), Result
LOOKUP Result, (35, 40, 58, 62, 79, 83), Result
DEBUG "I= ", #I, "Result=", #Result, CR
PAUSE 100
NEXT
Demo Program (LOOKDOWN.bs2)
' This program uses LOOKDOWN to determine the number of decimal digits in a number.
' The reasoning is that numbers less than 10 have one digit; greater than or equal
' to 10 but less than 100 have two; greater than or equal to 100 but less than 1000
' have three; greater than or equal to 1000 but less than 10000 have four; and greater
' than or equal to 10000 but less than 65535 (the largest number we can represent in
' 16-bit math) have five. There are two loopholes that we have to plug: (1) The number
' 0 does not have zero digits, and (2) The number 65535 has five digits. To ensure that
' 0 is accorded one-digit status, we just put 0 at the beginning of the LOOKDOWN list.
' Since 0 is not less than 0, an input of 0 results in 1 as it should. At the other end
' of the scale, 65535 is not less than 65535, so LOOKDOWN will end without writing to the
' result variable, NumDig. To ensure that an input of 65535 returns 5 in NumDig, we just
' put 5 into numDig beforehand.
'{$STAMP BS2} 'STAMP directive (specifies a BS2)
I VAR WORD ' Variable (0-65535).
NumDig VAR NIB ' Variable (0-15) to hold # of digits.
FOR I = 0 TO 1000 STEP 8
NumDig = 5 ' If no 'true' in list, must be 65535.
LOOKDOWN I, <[0, 10, 100, 1000, 10000, 65535], NumDig
DEBUG "I= ", REP " " \ ( 5 – NumDig ), DEC I, TAB, "digits=", DEC NumDig, CR
PAUSE 100
NEXT
1
2
e
2
sx
2
p
2
NOTE: This is written for the BS2
but can be used for the BS2e,
BS2sx and BS2p also. Locate the
proper source code file or modify
the STAMP directive before
downloading to the BS2e, BS2sx or
BS2p.
Содержание BASIC Stamp 1
Страница 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...