Question using an array

Hi
I have an array of pin numbers they are part of a library and I'm using them with interrupts
External Interrupts and with Timer 3 output compare. I have declared the array as volatile I was wondering if I could put this array in flash memory since it the values never change? How would I do that inside a library? I'm using the values stored for digitalWrite and digitalRead. It works as I have it just fine but I'm wasting 12 bytes on sram do it the way I have below I'm using the 2560 board.
Thanks
Don

// variable used by interrupts 
volatile uint8_t eomFlag = 0;
volatile uint8_t rxPins[] = {5,6,7,9,10,11};         // would like to put in flash memory
volatile uint8_t cdPins[] = {21,20,19,18,02,03};  // would like to put in flash memory

There is no point in making variables volatile, if they don't change.

If the values don't change, use them as 'const' and not 'volatile'.
The 'volatile' is for variables that can be changed in an interrupt, without knowing when that happens.

To place code in Flash, see this, PROGMEM - Arduino Reference
The problem is that you can't use them as variables, you have to use a function to read them. The pgm_read... functions.

Thank for your reply Nick.
I changed those arrays too below and the library still operates perfectly.

#include <avr/pgmspace.h>

prog_uchar rxPins[] = {5,6,7,8,9,10,11};
prog_uchar cdPins[] = {21,20,19,18,02,03};

Oh? Strange. :slight_smile:

You need also to add the PROGMEM keyword to put them into flash memory.
If they are in flash memory, you can't use them anymore. You will need those pgm_read.... functions.

That type has the keyword:

typedef unsigned char PROGMEM prog_uchar;

I didn't realize there is special read functions to fetch values from flash memory.
I work on that thanks guys.