Hi
TL;DR:
32x16x3 array takes more memory than the same data as a long procedural list of instructions, why?
Long version:
I have a 32x16 LED matrix and I want to display colour images that I create on it, like a colour bitmap.
However, the bitmap draw function with the Adafruit library is monochrome only.
I worked out a way to use python in another software to sample the values of each pixel and literally generate a string of instructions to get the arduino to draw each pixel one at a time. That worked, but unsurprisingly took most of the memory on the arduino UNO and I could only get one image on there.
like this:
matrix.drawPixel(0,0,matrix.Color888(0,0,0));
matrix.drawPixel(0,1,matrix.Color888(0,0,0));
matrix.drawPixel(0,10,matrix.Color888(3,98,82));
matrix.drawPixel(0,11,matrix.Color888(3,98,74));
matrix.drawPixel(0,12,matrix.Color888(2,84,57));
matrix.drawPixel(0,13,matrix.Color888(0,0,0));
Next I tried using a similar method to create a 3D array (rows and columns for x and y, and three values for RGB. Here's a small test one I made manually:
uint8_t myArray[4][8][3] = {
{{255, 255, 255}, {100, 200, 255}, {255, 100, 200}, {255, 0, 0},{255, 255, 255}, {100, 200, 255}, {255, 100, 200}, {255, 0, 0},},
{{255, 200, 100}, {100, 200, 255}, {255, 100, 200}, {10, 100, 150},{255, 200, 100}, {100, 200, 255}, {255, 100, 200}, {10, 100, 150}},
{{255, 200, 100}, {100, 200, 255}, {255, 100, 200}, {10, 100, 150},{255, 200, 100}, {100, 200, 255}, {255, 100, 200}, {10, 100, 150}},
{{0, 255, 0}, {100, 200, 255}, {255, 100, 200}, {0, 0, 0},{0, 255, 0}, {100, 200, 255}, {255, 100, 200}, {0, 0, 0}},
};
This nearly worked too, except it actually took up more memory than just hard coding every value like before, and when storing a full 32x16x3 array it actually caused the whole thing to fail and the LED matrix went mental.
I am resigned to the fact that I will probably never get more than one image on to the unit this way, but now I am curious as to why the array took more memory and whether there's a way to optimize it. I suspect its to do with how hard coded values get compiled or something? I tried using #define but that made no difference.
I am a total noob to low level programming! It's tricky!!
Thanks
PS here's an image of the first attempt that worked:
