Pages: [1]   Go Down
Author Topic: Menu on LCD: strings, multi-dimensional arrays?  (Read 1352 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys.  I've searched around a bit before posting, but I wasn't sure what to look for, so forgive me if this has been answered.

What I'm looking to accomplish is the following:

Have a series of user-navigable menus drawn using the liquidCrystal library.

I've come up with some pseudo-code for what I want to do, but it's long enough that I'll just try and summarize what I have in mind.

I'd like to have:
  • an int corresponding to which "menu" the user is in.
  • an int corresponding to the selected "item" in that menu
  • a bool corresponding to whether they are "editing" that item's "value"
  • an array of names of "menu"s to be written to the screen for the user (id corresponds to the menu int.)
  • an array of names of "items" in each menu (again the id's would match my "selected item" int)
  • an array of values for each "item" in each "menu"  

I'd ideally build in such a way that when I'm drawing the menu I can just use these variables plugged into the same function no matter what the menu structure looks like.  This way, if I need to add items to the menu later it's no big deal -- I just adjust the lengths of the arrays and that's it.

So here are the questions I have:
  • what's the best way to structure this?  I'm thinking of a 2- or 3-dimensional array, but this starts to get complex when I try and think about how to link the values of items to their names.  Another thought was to create a new class that handles all of this data stuff, but I don't know C well enough to know if that's a good approach.
  • what's the best way to handle the large number of strings I'll be needing to keep track of?  If it makes it any easier, I know they'll all be less than a certain length, and can pad them out to be all the same length with whitespace.
  • The values of the menu items will be in a variety of formats, including some which are a list of text-based options that correspond to numeric values.  (one example being the string "1/8000" which would represent the int 125)
  • Is there a better way to be doing this?  I don't have any *real* formal training in CS, so I'm sure there are better ways to do this.

« Last Edit: August 31, 2010, 10:44:33 pm by willis » Logged

Melbourne, Australia
Offline Offline
Full Member
Karma: 0
Posts: 219
Have you tried turning it off and on again?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

(In my opinion) I think that "Linked Lists" are a good way of doing menus.

There is a section for this in the book "C: The Complete Reference" (great book)

I found something for you to look at  Basically, you use a "next"/"previous" approach, and I have found it to be a successful way to use XML data.  The trick is that you add another pointer called "parent"; you go through the list and print every element with that parent.

There is also a library out there somewhere if you keep digging around.

If you have lots of strings, it is best to look into PROGMEM

Seattle, WA USA
Offline Offline
Brattain Member
Karma: 642
Posts: 50367
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is also a memory library that you might want to look at:

Pages: [1]   Go Up
Jump to: