Shop OBEX P1 Docs P2 Docs Learn Events
LOOKUP command? — Parallax Forums

LOOKUP command?

72sonett72sonett Posts: 82
edited 2013-03-05 14:12 in BASIC Stamp
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;
[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

  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-05 13:34
    The usual situation is that a program hits a LOOKUP command with an index to a single value that is picked out of the list, and then the program goes on to do something with that value. If the index points outside the list, the value is indeed whatever it had before execution of LOOKUP.

    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.
  • 72sonett72sonett Posts: 82
    edited 2013-03-05 14:12
    Thanks.
    After some trial & error I found that the trailing space in the "PARALLAX_" string effectively blanks the remaining positions of the LCD;
    Foto-DYOQ7UYY.jpg

    So this loop does exactly what I want;
    [SIZE=2][FONT=courier new]maxchar  CON   15
    .
    .
    [/FONT][/SIZE][FONT=courier new][SIZE=2]FOR i = 0 TO maxchar
      LOOKUP i, ["PARALLAX "], char   ' use list to store text     
      GOSUB Sendtext                  ' send character to LCD
    NEXT
    .
    .
    [/SIZE]
    [/FONT]
    

Sign In or Register to comment.