Disclaimer: I just started using C++ and I'm a bit of a beginner. Keep that in mind as your answering.
So I recently bought my first Arduino. It's a customized one and it has an 8x8 display attached to it. To display something on the display, the company I bought it from recommends storing the instructions for the display in a two-dimensional byte array.
I now have a longer animation I want it to play, so I researched and found PROGMEM which lets me store much more data. So I write something along the lines of:
const byte frames[2][8] PROGMEM {
{
B10000100,
B10000100,
B10000100,
B10000100,
B10000100,
B10000100,
B10000100,
B10000100,
},
{
B10010100,
B10010100,
B10010100,
B10010100,
B10010100,
B10010100,
B10010100,
B10010100,
}
};
void setup() {
arduino.begin();
}
void loop() {
arduino.printImage(frames[0]);
delay(1000);
arduino.printImage(frames[1]);
delay(1000);
}
After compiling, it throws a few errors at me:
warning: invalid conversion from 'const byte* {aka const unsigned char*}' to 'byte* {aka unsigned char*}' [-fpermissive]
arduino.printImage(frames[0]);
~~~~~~~~^
This did not worry me as much and I just ignored those. After uploading, however, the display just showed arbitrary patterns instead of the lines I told it to draw.
After I removed the PROGMEM, it worked flawlessly, however, the memory wasn't big enough to store the array (not the one I provided as an example).
I could think of two reasons:
- In the official documentation of PROGMEM, it states that you have to get the variables back into memory. However, none of the methods they provided worked for me.
- In a similar question on ASE, both answer and comments state that nested arrays aren't supported, but my knowledge of C++ isn't good enough to understand the answer.
strcpy_P(buffer, (char *)pgm_read_word(&(frames[1]))); arduino.printImage(buffer);
However, it just tells me that'buffer' was not declared in this scope