Text Lookup
KAD3
Posts: 3
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.
·
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
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
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
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.
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:
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:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office