This works using avr-gcc compiler version 4.7.2. If you are using the older version bundled with standard Arduino IDE there will need to be some minor changes with number of brackets and casting to make it compile. But you will be able to google that using the snippets above.
The code above copies the menu strings to flash memory and retrieves them from there rather than the very limited RAM. This leaves RAM for running programs rather than storing text.
As you are using the print functionality you can avoid using the temporary buffer as the Print library can handle PROGMEM data.
It needs a little help, but still worth it if ram is tight.
You've saved a whole lot of RAM by putting your arrays in flash memory but then waste it all by loading their contents into a similar (and wasteful) sized array stored in RAM thereby negating your memory savings.
Get rid of menuList[] and use the the data direct from the PROGMEM array as shown in my snippets or those by pyro_65.
lemming:
You've saved a whole lot of RAM by putting your arrays in flash memory but then waste it all by loading their contents into a similar (and wasteful) sized array stored in RAM thereby negating your memory savings.
Get rid of menuList[] and use the the data direct from the PROGMEM array as shown in my snippets or those by pyro_65.
I realize this but the menu function I wrote uses the menuList array and would need a major rewrite to remove it. For now my main concern has been addressed; I ran out of memory and with your help I have regained some of it. My initial goal is to get the program finished. Once I have it finished and fully working I can revisit the menu function. I am still very new to the Arduino and C/C++ so I sometimes I have to compromise so I can progress.
michinyon:
There are several problems with your original post, that I can see.
The first problem is that your array would have to be sized for the largest of all the strings you want to put in it. That wastes a lot of space.
The wasted space was a trade off. At the time I wrote the menu function I did not know about pointers and I was having trouble with strings. Later I will update the menu function.
michinyon:
And the second problem is that you have 9 strings not 8.
This is due to how my menu function works. Element 0 is a static title that does not scroll. Elements 1-8 are the actual menu options which scroll up and down. Therefore, actual menu items = 8. I found it easier to work this way.