Shop OBEX P1 Docs P2 Docs Learn Events
string input LOOKUP — Parallax Forums

string input LOOKUP

deansdeans Posts: 9
edited 2012-01-02 05:13 in BASIC Stamp
Hello everybody,

I am trying to use LOOKUP to display a set of characters received over serial port on a 7-segment LED.
The string is received but LOOKUP seems not to be operating correctly on the string.

The characters are not displayed correctly, I can see from the DEBUG feedback that the LOOKUP does not ouput the values from the table.

Can anybody tell me what this is? A matter of formatting the input differently? But then how?
Below you can find the sample code from the exercises that I expanded to attempt to do what I would like to do...

Sincerely

Dean

' {$STAMP BS2}
' {$PBASIC 2.5}

serStr VAR BYTE(5)
SERIN 16, 16468, [STR serStr\5]

' Patterns of 7-Segment Display to create letters
A CON %11110101
b CON %00110111
C CON %01100011
d CON %10010111
E CON %01110011
F CON %01110001
H CON %10110101
I CON %00100001
n CON %00010101
p CON %11110001
r CON %00010001
S CON %01110110
t CON %00110011

_ CON %00000000


OUTH = %00000000
DIRH = %11111111

index VAR BYTE

DO

DEBUG "index OUTH ", CR,
"

", CR

FOR index = 0 TO 4

LOOKUP 0, [serStr(index)], OUTH

DEBUG " ", DEC2 index, " ", BIN8 OUTH, " ", serStr(index), CR

PAUSE 400

NEXT
PAUSE 2000
LOOP

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2012-01-01 15:55
    Hi deans, you are not using LOOKUP correctly and this app really needs LOOKUP and LOOKDOWN working together. Here's an example based around the code you already have but with LOOKDOWN included. Take a look at these instructions in the manual and take note of how they both use a value or index to access the contents of the tables within the square brackets and then they both store a value in a variable at the end of the instruction.
    value VAR Byte
    index VAR Byte
    serStr VAR Byte(5)
    
    A CON %11110101
    b CON %00110111
    C CON %01100011
    d CON %10010111
    E CON %01110011
    F CON %01110001
    H CON %10110101
    I CON %00100001
    n CON %00010101
    p CON %11110001
    r CON %00010001
    S CON %01110110
    t CON %00110011
    
    serStr(0)="A"
    serStr(1)="b"
    serStr(2)="C"
    serStr(3)="d"
    
    
    FOR index = 0 TO 3
    
    LOOKDOWN serStr(index),["AbCdEFHInprst"],value
    LOOKUP value,[A,b,C,d,E,F,H,I,n,p,r,s,t],OUTH
    
    DEBUG serStr(index)," ",DEC value,CR ,BIN8 OUTH,CR
    
    NEXT
    

    Jeff T.
  • deansdeans Posts: 9
    edited 2012-01-02 05:13
    Thank you Jeff.
Sign In or Register to comment.