Ausgabe von Text aus PROGMEM [gelöst]

Ich habe mal wieder ein Pointer-Problem (wie so oft sitzt das Problem vor dem Bildschirm).

Wie muss ich in printPROGMEMstring(char c) den Parameter deklarieren und wie muss ich ihn beim Aufruf übergeben?

const char s1[] PROGMEM = {"String, der nicht im SRAM stehen soll\n\0"};
const char s2[] PROGMEM = {"String, der auch nicht im SRAM stehen soll\n\0"};

void printPROGMEMstring(char c){
  for (int x = 0; x<strlen_P(c); x++){
    Serial.print(char(pgm_read_byte_near(&c + x)));
  }
}


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

printPROGMEMstring(s1);
printPROGMEMstring(s2);

}

void loop() {
  // put your main code here, to run repeatedly:

}
const char s1[] PROGMEM = {"String, der nicht im SRAM stehen soll\n\0"};
const char s2[] PROGMEM = {"String, der auch nicht im SRAM stehen soll\n\0"};

void printPROGMEMstring(const char *c){
  for (size_t x = 0; x<strlen_P(c); x++){
    Serial.write(pgm_read_byte_near(c + x));
  }
}

void setup() 
{
  Serial.begin(9600);
  printPROGMEMstring(s1);
  printPROGMEMstring(s2);

}

void loop() 
{

}

Indem Du deiner Funktion auch sagst, dass Du einen Pointer übergibst:

void printPROGMEMstring(char *c){   // << Parameter als Pointer deklarieren
  for (int x = 0; x<strlen_P(c); x++){
    Serial.print(char(pgm_read_byte_near(c + x))); // << hier Pointerarithmetik ( 'c' ist jetzt schon eine Adresse )
  }
}

ok, combie war schneller - und Serial.write statt Typwandlung ist auch einfacher :wink:

Danke!

So einfach... kaum macht man es richtig, funktioniert es.

void printPROGMEMstring(char *cp){   // << Parameter als Pointer deklarieren
  while (char c =  pgm_read_byte_near(cp)) {
    Serial.write(c); 
    cp++;
  }
}

noch einen Tick einfacher.