I have the following in
Codes.h, which I access by clicking on the tab within the Arduino Software. So I know the sketch is being loaded properly with the header file.
#ifndef __CODES_H__
#define __CODES_H__
PROGMEM prog_uint16_t show_hide_info[] = { 4216, 8900, 4380, 580, 500, 600, 500, 580, 1620, 580, 500, 600, 500, 580, 500, 600, 480, 600, 500, 580, 1620, 580, 1620, 600, 500, 580, 1620, 580, 1620, 600, 1600, 600, 1620, 580, 1620, 600, 500, 580, 1620, 580, 500, 600, 1600, 600, 500, 580, 1620, 580, 500, 600, 1620, 580, 1620, 600, 480, 600, 1620, 580, 500, 600, 1600, 600, 500, 580, 1620, 580, 500, 600, 39300, 8860, 2160, 580 };
#endif
I then have in my code a method that uses the
show_hide_info[] array.
The problem is that when I try to access the array in the header file it doesn't contain any values.
Instead if I declare the above
PROGMEM above the
setup() method it does contain values.
Not quite sure why I'm getting this problem. I can confirm I've declared my header file properly by doing the following in my sketch.
#include "Codes.h"This is an example of how I use the array:
void sendCode(prog_uint16_t inArray[], int nLimit) {
unsigned int arr[nLimit];
unsigned int c;
int index = 0;
while ((c = pgm_read_word(inArray++))) {
arr[index] = c;
index++;
}
for (int i = 0; i < nLimit; i=i+2) {
Serial.println(arr[i]);
Serial.println(arr[i+1]);
}
}
Nothing outputs in the console if I try to use the array in the header file. It only works if I declare it within my actual main sketch program.
I know it's not a problem with the array itself or my method as a simple string or int does not work either. Very strange.