i'm so ashamed.
but maybe i can help you uncerstand what's going on...
this declares a zero terminated array of characters, i.e. a string, in program memory.
- Code: Select all
const prog_char PROGMEM stringTest[] = "Test working?";
this declares an array, (a very short array), of addresses of strings in program memory. note that these addresses are 16 bit values.
- Code: Select all
PGM_P PROGMEM stringTestTable[] = { stringTest };
this will read the address of stringTest from program memory.
- Code: Select all
(char*)pgm_read_word(&(stringTestTable[0]))
an array reference without a subscript gives the address of the array, thus "stringTest" resolves to the address of stringTest.
stringTestTable is an array of string addresses, so "stringTestTable[0]" resolves to the address of stringTest.
the difference between the first and third examples is that in the first example the address resolves at run time and in the third it is resolved at compile time. this doesn't really seem right until you consider that data stored in program memory are implicitly const and so will not be altered at run time.
this means that the third example will run faster than the first and in this case would be the one you want to use. you would want to use the first example in the case where your stringTestTable is longer than one entry and you are using a variable index, because that reference would not be resolvable at compile time.
so...
- Code: Select all
int i = 0;
Print(stringTestTable[i]);
... should
not work.
but i've been wrong before. at least twice that we know of.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more