Hello everybody!
I am working on a project that is not small by any measure and im now starting to think about memory footprint..
Im currently using previously defined strings, since i want to print many of the strings to both a 16x2char LCD as well as serial, and i figured it would be better to only store the string once.
// strings (got loads of them, about 20-30 more)
#define STR_FUNC "Function "
#define STR_IS_ON "is ON"
#define STR_IS_OFF "is OFF"
bool boolVar = false; // bogus boolean, to provide a example code that compiles
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print(STR_FUNC);
if (boolVar) {
Serial.print(STR_IS_ON);
}
else {
Serial.print(STR_IS_OFF);
}
}
-------------------------
Expected result: "Function is OFF"
Ive been investigating a bit, trying to find out if "my" way is a decent solution or if i should go for another alternative, but i find it hard to find any concrete answers..
Ive found two other options, both involving progmem.
The first is to add the F(string) macro, but from what i understand, i would then have to scrap my list of strings and instead use a string inside each print statement.
The other is to use:
const char CLI_STR_POWER[] PROGMEM = "POWER";
But from what ive gathered, i wont be able to use that progmem-stored variable in a Serial.print().
So, given that im using print from Serial as well as liquidcrystal, what is my best alternative to keep the memory usage to a minimum?