After my advanced Arduino project failed spectacular due to the stack and heap colliding, I have been working to change my code over from using Strings to char arrays. I understand the basics, but I have a question on how to store a char array in the flash memory of the Arduino, like F().
Code example, before changing to char arrays
error = True;
void loop(){
if(error = True){
throwError(F("Water low"));
}
}
void throwError(String warning){
Serial.println(warning);
//**Other stuff**
}
I would like to be able to store the char array that I call throwError() with in the program memory; How can I do this?
error = True;
void loop(){
if(error = True){
throwError( /* What goes here? */ );
}
}
void throwError(const char *warning){
Serial.println(warning);
//**Other stuff**
}
Well, this is suspect:
if(error = True){
hum
if(error == True){
larryd:
Well, this is suspect:
if(error = True){
hum
if(error == True){
Advantages of writing code on the forums and not in an IDE 
J-M-L:
have a look at PROGMEM
Perfect, thanks!
I'm not sure why, but the page on PROGMEM, as well as the Gammon Forum page on PROGMEM, do not discuss what you need in this case. Possibly it may not have existed in the compiler at the time those were written. You can reference a char array created with the F() macro using const __FlashStringHelper* . You may also want to overload the function so that it will work with regular character arrays as well, depending on how it is used in your code:
bool error = true;
void setup(){
Serial.begin(9600);
}
void loop(){
if(error == true){
throwError(F("Water low"));
char text[] = "Water still low";
throwError(text);
}
delay(1000);
}
void throwError(const __FlashStringHelper* warning){
Serial.println(warning);
//**Other stuff**
}
void throwError(char* warning){
Serial.println(warning);
//**Other stuff**
}