passing flash string param to a functiom

Hello,

I am trying to replace all my Serial.print… used mainly for debugging by a call to a function which will be given also the verbosity level at which the text should be printed

instead of if(verbosity>2)Serial.print(“bla bla”), simply report("bla bla, 2);

with some function
report(char* text, int level) if (level>verbosity) Serial.print(text);

Can someone tell how to do this?
Thanks
[edit] and of course all these strings I need to print should be in program memory as
Serial.print(F(“bla bla”)) to save ram space

The thread title does not seem to match your code or description. Can you please clarify where flash strings come into it ?

Oops
Yes, strings should be in flash. Otherwise no problem

Well, I'm not sure why you need to pass flash strings to a function, but this is how you do it:

const char PROGMEM test_text[] = "test_text";

void setup()
{
  Serial.begin(115200);

}

void loop()
{
  test_function(test_text);
  test_function((PGM_P)F("test_text_2"));
}

void test_function(PGM_P pgm_string)
{
  char this_char;

  do
  {
    this_char = pgm_read_byte(pgm_string++);
    Serial.print(this_char);
  } while (this_char != '\0');
  Serial.println();

  return;
}

fabulous!

btw, 115200 is much above the capacity of my hw :slightly_frowning_face:

You could use something like

void fPrint(const __FlashStringHelper* pmChars)
{
  Serial.println(pmChars);
}
void setup()
{
  Serial.begin(115200);
  fPrint(F("from Flash"));
}
void loop() {}

@Whandall: Thank you. I created a "report" function using your code, It works perfectly, saves me many tests and time printing and saves ram. Thank you