Using program memory

You can use program memory to store constants for example:-

const PROGMEM byte data[] = { 0xCA, 0x0C, 0x80, 0x81, 0x81, 0x81};

Then you can get at it using:-

value = pgm_read_byte_near(&data[index]);

What I would like to know is how to make "data" in the above line into a variable. That is something I could set up beforehand like:- p = &data and then use:-

value = pgm_read_byte_near(p[index]);

Of course this does not work, does anyone know the right syntax to make something like this work.

Thanks

Since data is an array, you'd need a pointer to point to the start of data.

byte *ptr = &data[0];

Then, you can use ptr anywhere you would have used data.

Thanks Paul, having previously declared:-

volatile byte *point;

when I try this I get:-

Arduino: 1.6.6 (Mac OS X), Board: "Arduino/Genuino Uno"
....
      point = &data[0];
           ^
exit status 1
invalid conversion from 'const byte* {aka const unsigned char*}' to 'byte* {aka unsigned char*}' [-fpermissive]

Edit:- changed variables to be consistent with the first post

OK solved it, I needed to use:-

volatile const byte *point;

Then it works a treat. Thanks again Paul.

I needed to use

Or a cast:

point = (byte *)&data[0];

Why is point volatile?

Why is point volatile?

Because it is being used in an ISR

edit: wrong place for this...

PaulS: Since data is an array, you'd need a pointer to point to the start of data.

byte *ptr = &data[0];

Then, you can use ptr anywhere you would have used data.

Question, is byte *ptr = &data[0]; the same as byte *ptr = data;

Question, is byte *ptr = &data[0]; the same as byte *ptr = data;

Yes. I prefer the former as it makes it explicit that you are pointing to the first element of the array. The second implicitly points to the first element of the array.

PaulS Point taken.