LOOKUP command?
72sonett
Posts: 82
I bought a Hitachi compatible LCD and got it to work, using the LOOKUP directive to send a character string to the LCD, like so;
This gives;
where I expected
as the help manual says;
but apparently 'char' keeps the last value it had after running out of the lookup list, not the value it had before entering LOOKUP.
Maybe I'm misunderstanding the help manual?
[FONT=courier new]' {$STAMP BS2sx} ' {$PBASIC 2.5} ' -----[ variables ]------------------------------------------------------- char VAR Byte ' stuff to send to LCD i VAR Byte ' index, temp variable ' -----[ Main Program ]---------------------------------------------------- Main: [/FONT][FONT=courier new] char= " " [/FONT][FONT=courier new] FOR i = 0 TO 15 LOOKUP i, ["PARALLAX!"], char ' use list to store text GOSUB Sendtext ' send character to 1x16 pos. LCD NEXT DEBUG CR char= "!" FOR i = 0 TO 15 LOOKUP i, ["PARALLAX "], char ' use list to store text GOSUB Sendtext ' send character TO LCD NEXT DEBUG CR END ' done ' =====[ Subroutines ]================================================== Sendtext: DEBUG char ' send to PC screen (instead of LCD) RETURN ' ====================================================================== [/FONT]
This gives;
PARALLAX!!!!!!!! PARALLAX
where I expected
PARALLAX! PARALLAX !!!!!!!!
as the help manual says;
If Index is beyond the end of the list, the result variable is unchanged. In the example above, if index were greater than {8}, the message would have reported the result to be {_} (or ! ) , because that's what result {char} contained before LOOKUP executed.
but apparently 'char' keeps the last value it had after running out of the lookup list, not the value it had before entering LOOKUP.
Maybe I'm misunderstanding the help manual?
Comments
You have LOOKUP in a loop. If you were to put your char = " " or char = "!" inside the loop, then it would act as you are expecting when i>9. Yes, it does then retain its most recent value.
After some trial & error I found that the trailing space in the "PARALLAX_" string effectively blanks the remaining positions of the LCD;
So this loop does exactly what I want;