I want to convert const char array in PROGMEM to String. How do I do this?
const char charArray[] PROGMEM = "Some text";
asked Aug 14, 2018 at 17:17
1 Answer 1
you can use a cast to __FlashStringHelper
to invoke the right constructor of the String class. It is the constructor which copies the char array from PROGMEM. __FlashStringHelper
is intended as return type for the F() macro.
const char charArray[] PROGMEM = "Some text";
void setup() {
Serial.begin(115200);
String s((const __FlashStringHelper*) charArray);
Serial.println(s);
}
void loop() {
}
answered Aug 14, 2018 at 17:35
-
That is right, but how do this in loop or another functions?Mohamad_Frm– Mohamad_Frm2018年08月14日 17:51:36 +00:00Commented Aug 14, 2018 at 17:51
-
PROGMEM is always global. and setup() is a function like every other so same way2018年08月14日 17:54:06 +00:00Commented Aug 14, 2018 at 17:54
-
Absolutely, but when I write this code in loop, the compiler will generate this error: conflicting declaration 'String s'Mohamad_Frm– Mohamad_Frm2018年08月14日 17:58:54 +00:00Commented Aug 14, 2018 at 17:58
-
Thanks so much. The compiler error was due to another part of my sketch.Mohamad_Frm– Mohamad_Frm2018年08月14日 18:16:37 +00:00Commented Aug 14, 2018 at 18:16
lang-cpp
that is not work
.... that statement provides no useful information .... describing the actual error would help