Shop OBEX P1 Docs P2 Docs Learn Events
Text Lookup — Parallax Forums

Text Lookup

KAD3KAD3 Posts: 3
edited 2004-11-15 05:08 in BASIC Stamp
Hi,

Is there away of associating text with a lookup table?

i.e.·
lookdown x, [noparse][[/noparse]56,55,54,53,52,49],text
lookup text, [noparse][[/noparse]Pump,Light,Door1,etc],y

Any comments would be appreciated.
·

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-11-15 02:37
    KAD3 -

    Directly, as you have shown it, the answer is no. Text or string processing is not something microcontollers do well. However, you may want to consider the following or a similar approach.

    Limit your "text" input manipulations to one unique letter or number as either/both have a unique numeric value and that value can be used to index into a EEPROM table which contains the full text. The EEPROM can be the one onboard the Stamp, or a separate EEPROM if you have more than what would be appropriate to store onboard.

    A fixed sized entry EEPROM table is the easiest to implement, but variable sized entry EEPROM tables can also be implemented with a bit more work. In the latter case you either need to store the length of each entry within the entry itself (in order to get to the next entry) or use a unique end-of-text delimiter for each entry.

    Regards,

    Bruce Bates
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-15 03:10
    KAD3:

    As Bruce pointed out, there is no string type in PBASIC, and string handling is a bit limited. What are you trying to accomplish -- there may yet be a solution.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • KAD3KAD3 Posts: 3
    edited 2004-11-15 04:33
    Re Text Lookup.

    I have a Lookdown table and then a Lookup table that associates a key press with a specific pin output. Each pin drives a relay via Current Amplier. This part works fine.

    I would like to display specific text via a serial LCD (pin 0) that lets me know what relay is activated (closed) For example; Relay1 ON or Pump ON etc. I have 16 relays all of which have unique control functions, as such I would like to display their staus.

    I can read the status OK, however I am struggling to find a way to associate specific text to each relay. Perhaps IF OUT2 = 1 then Display.... might work - however with 16 relays, I thought a Lookup table would be simpler. Perhaps not.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-15 05:08
    What you need, actually, is a LOOKUP table to point to strings stored in an EEPROM table.· Here's how to store strings:

    Msg1    DATA    "BASIC ", 0
    Msg2    DATA    "Stamp", CR, 0  
    


    By terminating with a zero (these are called z-strings), you can embed characters like carriage returns as shown above.· Now you can use LOOKUP with an index value to find the first character of the string:

      LOOKUP theMsg, [noparse][[/noparse]Msg1, Msg2], eeAddr
    


    Now that you have the first character of the desired string, you can send the message, character-by-character, to your display.· Here's an example using DEBUG:

    Print_Msg:
      DO
        READ eeAddr, char
        eeAddr = eeAddr + 1
        IF (char = 0) THEN EXIT
        DEBUG char
      LOOP
      RETURN
    


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.