I can't understand this error. It simple scketch should print some strings, but, I can't make this work.
If you try this example it print everything in the memory (reasonable).
But, if you uncomment the if line (if (character == 0) endthis = 0;), it should print each line every 0.5 seconds. But, it print a infinite number of same character.
I not understand what is happens. Can you help me?
#include <avr/pgmspace.h>
prog_char string_0[] PROGMEM = "0-0-0-0-0-0-0-0-0-0"; // "String 0" etc are strings to store - change to suit.
prog_char string_1[] PROGMEM = "1-1-1-1-1-1-1-1-1-1-1-1-";
prog_char string_2[] PROGMEM = "2-2-2-2-2-2-2-2-2-2-2";
prog_char string_3[] PROGMEM = "3-3-3-3--3-3-3-3-3-3-3-3";
prog_char string_4[] PROGMEM = "4--4-4-4-44-4--4-4-4-44";
prog_char string_5[] PROGMEM = "5-5-5-5-5-5-5-5-5-5-5-5-5-55";
PROGMEM prog_char *string_table[] = // change "string_table" name to suit
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5
};
void setup()
{
Serial.begin(9600);
}
void loop()
{
for (uint8_t i = 0; i < 6; i++)
{
char character;
Serial.print("String ");
Serial.print(i);
Serial.print(": ");
prog_char* str = string_table[i];
// while((c = pgm_read_byte(str++))) Serial.write(c);
uint8_t endthis = 1;
do {
character = (char)pgm_read_byte(str);
Serial.write(character);
if (character == 0) endthis = 0;
str++;
} while(endthis == 1);
Serial.println();
delay( 500 );
}
}