Skip to content

Instantly share code, notes, and snippets.

@crazylion
Created September 10, 2013 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazylion/6510870 to your computer and use it in GitHub Desktop.
Save crazylion/6510870 to your computer and use it in GitHub Desktop.
#include <avr/pgmspace.h>
prog_char string_0[] PROGMEM = "String 0"; // "String 0" etc are strings to store - change to suit.
prog_char string_1[] PROGMEM = "String 1";
prog_char string_2[] PROGMEM = "String 2";
prog_char string_3[] PROGMEM = "String 3";
prog_char string_4[] PROGMEM = "String 4";
prog_char string_5[] PROGMEM = "String 5";
char buffer[30];
PROGMEM prog_char *string_table[] = // change "string_table" name to suit
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5 };
PROGMEM prog_char *string_table1[] = // change "string_table" name to suit
{
string_5,
string_4,
string_3,
string_2,
string_1,
string_0 };
int count=0;
prog_char **charPtr;
void setup()
{
Serial.begin(9600);
}
void loop()
{
/* Using the string table in program memory requires the use of special functions to retrieve the data.
The strcpy_P function copies a string from program space to a string in RAM ("buffer").
Make sure your receiving string in RAM is large enough to hold whatever
you are retrieving from program space. */
if(count%2==0){
charPtr = &(string_table[0]);
}
else{
charPtr = &(string_table1[1]);
}
// Serial.println(charPtr);
// Serial.println(string_table[0]);
Serial.println("======");
strcpy_P(buffer, (char*)pgm_read_word((charPtr)));
Serial.println( buffer );
// Serial.println("====");
delay( 500 );
// for (int i = 0; i < 6; i++)
// {
// strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
// Serial.println( buffer );
// delay( 500 );
// }
count++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment