Hello,
I'm learning how to store arrays of strings in PROGMEM, and after looking through various threads, and trying a few examples, here is what I've put together.
- Store an array of strings in PROGMEM
- Create a table of pointers (that's what I think it's called).
- Choose the right array element through a variable called current_clue.
- Copy the array element value to another array.
- Print that array.
It all works fine, however is there a more efficient/better way to do this? Thanks!
const char string_0[] PROGMEM = "Welcome to your ";
const char string_1[] PROGMEM = "Where no shrimp drown";
const char string_2[] PROGMEM = "Would you like some ";
const char string_3[] PROGMEM = "A place for bubbly ";
const char string_4[] PROGMEM = "Where short skirts ";
const char string_5[] PROGMEM = "Where our names are ";
const char string_6[] PROGMEM = "Where the water meets";
const char string_7[] PROGMEM = "This is life... ";
const char string_8[] PROGMEM = "A pink blouse, fairy ";
const char string_9[] PROGMEM = "Adventure ";
const char string_10[] PROGMEM = "in the hot sea... ";
const char string_11[] PROGMEM = "eye cream? ";
const char string_12[] PROGMEM = "and sunsets... ";
const char string_13[] PROGMEM = "hunt their prey... ";
const char string_14[] PROGMEM = "locked... ";
const char string_15[] PROGMEM = "the last land... ";
const char string_16[] PROGMEM = "Innit! ";
const char string_17[] PROGMEM = "lights, and a smile...";
const char* const string_table1[] PROGMEM = {string_0, string_1, string_2, string_3, string_4, string_5, string_6, string_7, string_8 };
const char* const string_table2[] PROGMEM = {string_9, string_10, string_11, string_12, string_13, string_14, string_15, string_16, string_17 };
char clue_line_one[25];
char clue_line_two[25];
// The actual sketch advances or retreats current_clue programmatically
int current_clue = 5;
void setup() {
Serial.begin(9600);
}
void loop() {
strcpy_P(clue_line_one, (char*)pgm_read_word(&(string_table1[current_clue])));
strcpy_P(clue_line_two, (char*)pgm_read_word(&(string_table2[current_clue])));
Serial.println(clue_line_one);
Serial.println(clue_line_two);
delay(5000);
}