Hi,
I am developing a graphical menu to drive a few banks of relays and want to save on memory space, the program uses 71% for global vaariables. I can use some help on this.
The menu is stored as an array of MenuItems, where each menuItem is a struct.
struct MenuItem {
char text[15];
byte bank;
byte position;
static byte length ;
};
To initialize the menu I use a function addItem().
void addItem(const String text, boolean status, byte bank, byte position) {
byte n = MenuItem::length;
text.toCharArray(item[n].text, STRLEN);
item[n].bank = bank ;
item[n].position = position ;
MenuItem::length ++;
}
I call this function 24 times during setup, for example
addItem("Wifi", false, 2, 4);
addItem("USB", false, 1, 5);
For each call to addItem a String object is created that is copied to a char array in the function body. I think the String objects remains in memory long after the function call. Is that true? If so, do they live during setup() or during program life? Is there another, more efficient, way to pass the menutext to the function?