Now I would like to minimize the amount of SRAM used by the program.I have read multiple times than using String is not always a good idea.
Since the message are known, what would be the best way to do this ?
I have about 80 differents messages that could potentially be printed. I supposed I could put them all in an array and use the array index to access them but it would be hard to maintain the code b/c I would need to remember that MsgX is in the position Y in the array.
So some sort of mapping seems to make sense.
What's the "best practice" for such problem ?
Would something like this make sense ?
One problem with that function is that it copies the message that you want to print onto the stack; so during the printing to the display you will loose e.g. 20 bytes; after that, it will be available again.
One way to solve that is to use a reference which will only place the reference on the stack (2 bytes on an AVR based board).
I don't know how the Teensy LC compiler decides what variables go into SRAM and what variables stay in FLASH. If all string literals go into FLASH then using character pointers and not String objects should keep them in FLASH. Since String objects are designed for dynamic size changes I would assume that any string literal you copy into a String object would have to go into SRAM.
Also I do have a few messages that are fairly the same (e.g. Fct 1, Fct 2, etc)
Could I perhaps only keep the word "Fct" in the array and dynamically append the integer ? But then how would I append the digits to MSG?
That won't work on an UNO/Nano/Mega because the F() macro only works on string literals.
It will probably work on a Teensy LC because, on devices without PROGMEM, the F() macro only exists for compatibility and does nothing. Of course, if it doesn't do anything, you don't need to use it.