help with accessing array using flash library

Hello, everyone.

I recently discovered that a) there is something called sram, and b) my project has run out of it. For that reason I need to start figuring out how to use PROGMEM, and from my googling and futzing around it appears using the flash library will make that a lot easier. However, I am not quite grasping the syntax I need to use to call from the arrays I (think I have) placed into flash memory using the flash library.

For instance, my program relies on several arrays that looked something like this:

int arrayOne[] =               
  24, 26, 28, 29, 31, 33, 35,  
  36, 38, 40, 41, 43, 45, 47,   
  48, 50, 52, 53, 55, 57, 59,   
  60, 62, 64, 65, 67, 69, 71,  
  72, 74, 76, 77, 79, 81, 83,   
  84, 86, 88, 89, 91, 93, 95,   
  96, 98, 100, 101, 103, 105, 107,     
  };

Later in the program, I accessed these arrays like this:

 variable= (mappedVariable[arrayOne]);

... which worked fine.

Now using the flash library, I made the array look like this:

FLASH_ARRAY(int, arrayOne, 
  24, 26, 28, 29, 31, 33, 35,   
  36, 38, 40, 41, 43, 45, 47,  
  48, 50, 52, 53, 55, 57, 59,   
  60, 62, 64, 65, 67, 69, 71,   
  72, 74, 76, 77, 79, 81, 83,   
  84, 86, 88, 89, 91, 93, 95,  
  96, 98, 100, 101, 103, 105, 107, 
  );

... but accessing the FLASH_ARRAY as I did the "normal" array gives me the following error message:

no match for 'operator[] in mappedVariable[arrayOne]'

is there a syntax I can use to replace

 variable= (mappedVariable[arrayOne]);

so that it works with the FLASH_ARRAY?

I'm not familiar with the FLASH_ARRAY feature, however you can use PROGMEM to put data into the flash and then access that data using a couple of functions. Take a look at PROGMEM - Arduino Reference.

int arrayOne[] =               
  24, 26, 28, 29, 31, 33, 35,  
  36, 38, 40, 41, 43, 45, 47,   
  48, 50, 52, 53, 55, 57, 59,   
  60, 62, 64, 65, 67, 69, 71,  
  72, 74, 76, 77, 79, 81, 83,   
  84, 86, 88, 89, 91, 93, 95,   
  96, 98, 100, 101, 103, 105, 107,     
  };

Since all those values are byte sized, why are you using twice as much space for the array as you need to?

Actually I changed from int to byte awhile ago but still have hit an sram wall.

Actually I changed from int to byte awhile ago but still have hit an sram wall.

Then why did you post obsolete code?

As it looks you have to use these:

// read back a 2-byte int
 displayInt = pgm_read_word_near(charSet + k)

// read back a char 
myChar =  pgm_read_byte_near(signMessage + k);

PaulS:

Actually I changed from int to byte awhile ago but still have hit an sram wall.

Then why did you post obsolete code?

... as I am not very familiar with the flash library, I chose to temporarily revert to int when rewriting my code as that is what is used in the examples. I was trying to replicate the example given as closely as possible so that if it didn't work I would know that it isn't because I did something like change byte when the example uses int. I know that it shouldn't matter but as you can see I am struggling with the basic usage of the library and it helped me to rule out potential problems implementing it. Once I saw it work with int I would try it with byte.

That having been said, what advice would you have given me if I happened to post the same question using byte instead of int?

That having been said, what advice would you have given me if I happened to post the same question using byte instead of int?

The same I give anyone that has a coding issue and posts only a snippet. Post all of your code. The snippets you posted do not make sense.

int arrayOne[] =               
  24, 26, 28, 29, 31, 33, 35,  
  36, 38, 40, 41, 43, 45, 47,   
  48, 50, 52, 53, 55, 57, 59,   
  60, 62, 64, 65, 67, 69, 71,  
  72, 74, 76, 77, 79, 81, 83,   
  84, 86, 88, 89, 91, 93, 95,   
  96, 98, 100, 101, 103, 105, 107,     
  };

 variable= (mappedVariable[arrayOne]);

The parentheses add nothing to this statement. The right side value is using an array as an index, which is clearly something that you could not have done before, and will not work now.