Design help - underlying data structure for LED menu.

Hi,

I am currently designing a menu with options that will display (max 8 characters) on a TM1638 LED module. I'm looking for some guidance on how to structure the data, like, do I use arrays, arrays of classes or what, to hold and modify the data.

My conceptual design so far is like this:

The data is on a grid like this:

Option1 value1 attribute1 OPtion1 value2 attribute2 . . Optionn valuen attributen

Imagine that there is a window that can show one option or value at a time. That is what will be displayed.

4 Buttons will be used to shift Down, Up, Left, Right. When the window is over a value ( not an option ), the up or down buttons will modify the value up or down but only if the attribute has a value of 'W' (...as in [u]R[/u]ead or [u]W[/u]rite access). So the up/down buttons have two functions depending on where the window is.

The design is to be table driven so that it is easily extendable or adaptable to other purposes.

I thought to use a 2 dimensional array, but there are different data types needed here. ( String, float and char ) so I'm unsure of the best way to proceed.

Please provide some recommendations on the best way to achieve what I am after.

Thanks

I thought to use a 2 dimensional array, but there are different data types needed here. ( String, float and char ) so I'm unsure of the best way to proceed.

The best way to proceed is to forget about the String class. There is NOTHING that the String class can do that can not be done faster, better, cheaper with strings.

Then, when you have different kinds of things that are logically related, structs are the way to go. A struct can hold many different bits, and kinds, of data. You could have a byte that describes what kind of data makes sense in this instance of the struct. You can have arrays, 2D even, of structs. I have some code at work that uses a tree of structs. Each node can have different kinds of data (although too many kinds doesn't make sense).

Paul's right. Use a struct. For example, if Option1 is "Fan 1", Value1 is rpm, and Attribute1 is On or Off, then the struct might look like:

struct myMenu{
   char option[8];
   int rpm;
   bool state;
};

If you need 10 of such elements, then define an array of structs:

myMenu selections[10]

Then, if you want to show the first option, you would use: myMenu[0].option to display the text of the first option (assuming you set that member to some string data.) Structures allow you to create "arrays for adults", because the elements of the array can have disparate members.

Thanks very much for your replies. I did not know about structs so I'll do some research on this and hopefully that will give me what I need to know.

Very much appreciate your input. Thank you!

Thanks @PaulS and @econjack. Finally got this done and released today. Your help was instrumental...

https://forum.arduino.cc/index.php?topic=351186.0