I've been seeing a lot of talk about the F() macro for using flash memory (progmem) for strings. But I haven't really found much online documentation on F()...
If one wants the same string to be output at several points in the script, is there way to assign a pointer to F() and then Serial.print() a reference to that pointer, or would one have to actually declare a const character array in PROGMEM at the top of the sketch to use with Serial.print()?
I think I may have answered my own question, but I'm not sure if I fully grok my own answer... (Probably because I'm new enough to C syntax that things like printf still have a hint of black magic to me...)
Yes, but instead of having Serial.print(F("your string here")); seven times in my sketch that I have to change seven times if I want to change the text to "your string is here", just have it declared once like a constant...
Maybe a better question for me to ask is for a link to a well written primer on using PROGMEM in C++ and/or Arduino's bastard (meant in the best possible way) take off of Processing...
Oh... now I see. The necessary casts and dereferencing are already part of the F() macro. So, using F() is just a shortcut to defining the PROGMEM constants at the beginning and then calling it once later. (I'm not going to call them variables because you can't (well really shouldn't, there might be an advanced trick I don't know about) change flash memory in one's code.)
This isn't part of the original questions, but I think my mind was just blown... It is perfectly acceptable to define two (or more) completely different functions with the same name, but different arguments. And the compiler knows which one you want to run based on what arguments are used when calling the function? So much for my thought that all function names should be unique...
Something else, that is very usefull.
It is possible to assign a value to a parameter and omit that when calling the function.
// Function
void Test( int x, int y=8)
{
Serial.print( x);
Serial.print( ", ");
Serial.println( y);
}
// Calling with or without second parameter.
Test( 3, 5); // x=3, y=5
Test( 10); // x=10, y=8