Home:ALL Converter>How to retrieve an int array that is stored in a table using PROGMEM?

How to retrieve an int array that is stored in a table using PROGMEM?

Ask Time:2016-12-21T16:14:25         Author:ngeri

Json Formatter

I'm new to Arduino and currently learn to use PROGMEM to store variables so that I can save dynamic memory. I have 13 variables including these three below that I store using PROGMEM. Here are some of example of variables that I store and use it in my functions :-

const unsigned int raw_0[62] PROGMEM  = {2600,850,400,500,400,500,450,850,450,850,1350,850,450,450,400,500,400,450,450,400,450,450,450,450,400,450,900,850,900,850,900,450,450,850,900,850,900,850,450,450,900,450,400,450,400,900,450,450,450,400,450,450,450,450,400,450,450,450,450,400,450,};
const unsigned int raw_1[60] PROGMEM = {2600,850,450,450,450,450,450,850,450,850,1350,850,500,400,450,400,450,450,450,450,400,450,450,450,400,450,900,850,900,900,850,450,450,850,850,900,900,900,400,450,900,450,450,400,450,850,450,450,450,450,400,450,450,450,450,400,450,450,850,};
const unsigned int raw_a[100] PROGMEM = {3500,1700,400,450,450,1250,450,400,450,400,450,400,500,400,450,400,450,400,450,400,450,450,400,400,500,400,450,400,450,1300,400,450,450,400,450,400,450,400,450,400,450,400,500,350,500,400,450,400,450,1300,400,400,500,400,450,400,450,400,450,450,400,450,450,400,450,400,450,400,450,400,450,450,400,450,450,400,450,1250,450,400,450,400,500,400,450,400,450,400,450,400,450,400,450,1300,450,400,450,1250,450,};

Here is the table that store the variables. I learn this approach from Arduino website; https://www.arduino.cc/en/Reference/PROGMEM .

const unsigned int* const myTable[13] PROGMEM = {
  raw_0, 
  raw_1, 
  raw_2, 
  raw_3, 
  raw_4,
  raw_5,
  raw_6,
  raw_7,
  raw_8,
  raw_9,
  raw_a,
  raw_b,
  raw_c};

My problem is, how do I retrieve these variables using PROGMEM such as raw_1 and raw_a ? This is what I did but it did not work :-

unsigned int * ptr = (unsigned int *) pgm_read_word (&myTable [1]);
irsend.sendRaw(ptr,62,38);

Most of examples that I found, they use String or char datatype but in my case, I use array integer.

Author:ngeri,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/41258036/how-to-retrieve-an-int-array-that-is-stored-in-a-table-using-progmem
yy