Array

Hi,

How can I create an array like this char* MenusTXT[] = {"Some text here","More text here","And More text here"}; but inserting one item at a time?

This is what I need to do:

MenusTXT[0]="Some text here";
MenusTXT[1]="More text here";
MenusTXT[2]="And More text here";

Before you go very much further and run out of RAM, you may want to read about using PROGMEM for large numbers or arrays of constant strings.

You want to add menu items during run time?

Noting your limited SRAM and EEPROM and how PROGMEM can let you use your flash up... caveats...

You could run your menu array as an array of pointers then fill that with a pointer to each entry name string. It would be -fat- but it could work.

I'm using this:

char* MenusTXT[] ={"Menu 1","Menu2","Menu 2.1", "Menu 2.2","< Go Back", "Menu 3"};

int MenusParentIndex[] = {0, 0, 1, 1, 1, 0}; //I use this to make fathers e childs menus

char* MenusActions[]={"ActMenu1","","ActMenu2.1","ActMenu2.2","BACK","ActMenu3" }; //Name of the function to call when this key is selected

Now I was thing to make a function to create the menus and the relations easyer.
Something like this:

AddNewMenu( "Menu 1","ActMenu1", 0);
AddNewMenu( "Menu 2","ActMenu2", 0);
AddNewMenu( "Menu 2.1","ActMenu2.1", PreviousID);
....

So that's why I need to use char* MenusTXT[0]=""; ...

Does my menu make any sense?

Can I make this using PROGMEM?

pfonseka:
Does my menu make any sense?

This would be a really good clear, extensible way to handle things on a real computer where RAM is available. Not for Arduino.

Can I make this using PROGMEM?

No. PROGMEM is only for things that can be hard-coded and compile time. If you are really brave you can make the C preprocessor do some useful things for you. Or you can make a script to transform some useful declarative format into the required compile-time constants to drive your menus.

But Arduino is simply not the platform to try and handle this at runtime.

Bu I can use PROGMEM to stor an array like this MenusTXT[] ={"Menu 1","Menu2","Menu 2.1", "Menu 2.2","< Go Back", "Menu 3"}; ?

How can I do it?
How can I access MenusTXT[2] for example?
Will I be able to know the array length? I was using this before: int TotalMenus=(sizeof(MenusTXT) / sizeof(char *));

thanks

gardner:

pfonseka:
Does my menu make any sense?

This would be a really good clear, extensible way to handle things on a real computer where RAM is available. Not for Arduino.

Can I make this using PROGMEM?

No. PROGMEM is only for things that can be hard-coded and compile time. If you are really brave you can make the C preprocessor do some useful things for you. Or you can make a script to transform some useful declarative format into the required compile-time constants to drive your menus.

But Arduino is simply not the platform to try and handle this at runtime.

Bu I can use PROGMEM to stor an array like this MenusTXT ={“Menu 1”,“Menu2”,“Menu 2.1”, “Menu 2.2”,"< Go Back", “Menu 3”}; ?

Yes, with examples;
http://www.arduino.cc/en/Reference/PROGMEM

AWOL: From what he writes I am not sure that all the menu strings are not known at compile time. I can’t be sure from the description but he might want to make dynamic menus using fixed choices. That’s still going to use RAM but with few such menus at any one time (you only see 1) it’s not so far fetched compared to 8x8x8 soft-PWM led cubes is it?

He might get away with a very small version of it if he doesn’t do much else and keeps the strings real short. How many added menu strings can 1K EEPROM hold? 20 strings may be enough for his purpose?

The 2K SRAM is the worst limit. OTOH Arduino’s are made to be extended. Just to use a menu system would require adding a display, even if it’s a terminal on your PC screen. With added memory or storage what he wants wouldn’t be such a stretch of the hardware. Making it work with reasonable speed might be a stretch for the programmer though.

Thank you for your help, but I got losted on translation.

Did you said that I don't need to use PROGMEM because I have few menus?

I've alrready read that page but I can't access the array with a variable index

char* MenusTXT[] PROGMEM ={"Menu 1","Menu2","Menu 2.1", "Menu 2.2","< Go Back", "Menu 3"};

lcd.print(MenusTXT[0]); //works

int ID=0;
lcd.print(MenusTXT[ID]); //doesn't work

GoForSmoke:

Bu I can use PROGMEM to stor an array like this MenusTXT[] ={"Menu 1","Menu2","Menu 2.1", "Menu 2.2","< Go Back", "Menu 3"}; ?

Yes, with examples;
PROGMEM - Arduino Reference

AWOL: From what he writes I am not sure that all the menu strings are not known at compile time. I can't be sure from the description but he might want to make dynamic menus using fixed choices. That's still going to use RAM but with few such menus at any one time (you only see 1) it's not so far fetched compared to 8x8x8 soft-PWM led cubes is it?

He might get away with a very small version of it if he doesn't do much else and keeps the strings real short. How many added menu strings can 1K EEPROM hold? 20 strings may be enough for his purpose?

The 2K SRAM is the worst limit. OTOH Arduino's are made to be extended. Just to use a menu system would require adding a display, even if it's a terminal on your PC screen. With added memory or storage what he wants wouldn't be such a stretch of the hardware. Making it work with reasonable speed might be a stretch for the programmer though.

pfonseka:
Thank you for your help, but I got losted on translation.

Did you said that I don't need to use PROGMEM because I have few menus?

NOOOOOOOO!

You -might- get away with few menus because of PROGMEM.

Also, if you need to add menu strings, think about using the EEPROM.

I've alrready read that page but I can't access the array with a variable index

char* MenusTXT[] PROGMEM ={"Menu 1","Menu2","Menu 2.1", "Menu 2.2","< Go Back", "Menu 3"};

lcd.print(MenusTXT[0]); //works

int ID=0;
lcd.print(MenusTXT[ID]); //doesn't work

But that is not how the example shows. You need to copy the string from PROGMEM to SRAM as they do and then print the copy.