I'm using an Uno R3 with a 16 x 2 LCD and want to build a menu tree. The final tree will be quite large so the data needs to be in Flash memory as I will eventually need most of the RAM for other purposes. I have typedef'd a structure, declared a couple of strings and created two structures, but the compiler can't find them.
I have had this working in the past with a variety of commercial C compilers but the Arduino IDE seems a bit reluctant to co-operate. I think I need to use the "F()" construct somewhere, but I'm not sure where.
Some help would be gratefully accepted.
Here's the full test program and the compiler error messages:
BasicMenu:10: error: variable or field 'showLine' declared void
BasicMenu:10: error: 'menuLine' was not declared in this scope
BasicMenu:10: error: 'lineToShow' was not declared in this scope
BasicMenu:20: error: cannot convert 'char (*)[11]' to 'char*' in initialization
BasicMenu:21: error: cannot convert 'char (*)[16]' to 'char*' in initialization
BasicMenu.ino: In function 'void showLine(menuLine*)':
BasicMenu:24: error: 'setCursor' was not declared in this scope
To try and debug it, I've avoided using Flash memory completely and kept it all in RAM, but it still doesn't work. It's down to two errors, which are appearing on line 10; the first "int" declaration in the typedef.
But only the "struct menuL" declaration works in a function definition as follows:
/* Using the normal structure definition in the function declaration works */
void showMenuLine(struct menuL lineToShow) {
lcd.setCursor(lineToShow.xPos, lineToShow.yPos);
lcd.print(lineToShow.displayString);
}
/* Using the "typedef" definition in the function declaration fails to compile */
void showMenuLine(menuLine lineToShow) {
lcd.setCursor(lineToShow.xPos, lineToShow.yPos);
lcd.print(lineToShow.displayString);
}
I've been programming in C since the early 1980s and thought Arduino would be a great relaxed way to produce a few simple displays for our local Heritage Museum in my latter years. How wrong can one be!! I've been retired now for over 8 years and this is like being back in the office.
It's not that difficult. Of course, one needs to recognize that the Arduino is suited for and what is going to be a challenge. Menus are always going to be a challenge, since they imply waiting for a selection, and full-speed-ahead is the Arduino motto, not hurry-up-and-wait.