Datasheet
Chapter 4: Navigation Tips · Page 149
Let's take a second look at that LOOKUP command from Chapter 2, Activity #4. If
counter is 0, the LOOKUP command will copy 1046 to the note variable. If counter is
1,
LOOKUP will copy 1175 to the note variable. If counter is 2, 1319 will be copied to
note, and so on.
LOOKUP counter, [1046, 1175, 1319,
1397, 1580, 1760,
1976, 2093], note
Example Program: LookupExample.bs2
√ Enter, save, and run LookupExample.bs2.
√ Use the Debug Terminal to verify the relationship between the value
counter
stores and the number between the square brackets that gets stored in the
note
variable.
' Applied Robotics with the SumoBot - LookupExample.bs2
' {$STAMP BS2}
' {$PBASIC 2.5}
LedSpeaker PIN 5
counter VAR Byte
note VAR Word
DEBUG "Counter Note",CR,
"------- -------", CR
FOR counter = 0 TO 7
LOOKUP counter, [1046, 1175, 1319,
1397, 1580, 1760,
1976, 2093], note
DEBUG DEC counter, CRSRX, 9, DEC note, CR
FREQOUT 5, 500, note
PAUSE 25
NEXT
END
Your Turn
You can declare constants equal to the note values, and then use those constants in the
lookup table.