Hello!
First time posting on an arduino Forum like this. I apolagize for any mistakes I might make. I'm working on a project using an Arduino Mega 2560, WS2812 Leds and the FastLED.h library. Its a 32x16 LED Matrix that uses 512 LEDs. A simple display test takes 22% of the Dynamic Memory. My guess is my issue has something to do with memory or buffer or heap size (concepts I only have a vaque understanding of).
To be clear I've managed to successfully power and control the LEDs in general. I'm having specifc issues when I try to create animated pixel art. I can get up to 8 frames of animation to play but once I try and do 9 frames of animation there seems to be some sort of fundamental issue with the SRAM which I'm trying to work around.
I attempted to use some info I found here: https://docs.arduino.cc/learn/programming/memory-guide#buffer-size-control
Which is where the PROGMEM comes from on line 40. Lines 41-49 (49 is commented out to make the code work) each represent one frame of the animation. The animation is 16x8 pixels in display size and 9 frames long. It's the duck running across the screen.
It work with 8 frames (one frame must be commented out, doesn't matter which frame) but not with 9 frames. If I uncoment that line (line 47) and update the NUM_FRAMES accoringly the arduino "stops" during startup (or at least the serial communication stops). It doesn't continually reset and when I was messing around moving where birdPxf was initialized it woulds somtimes display a "messed up" version of the animation.
At the end of the day I'm pretty sure the issue has to do with the large 4D array and I'm kind of wondering if maybe I need to define the array in a different scope and then access it in a function in a different way. I would also be happy for an explination of what's going on and how could improve this code anyway. I'm a second year computer engineering major and this is a personal project.
Thanks in advance for the help!
Here's the code:
#include <FastLED.h>
#include <avr/pgmspace.h>
#define LED_PIN 3
#define NUM_LEDS 512
#define NUM_FRAMES 8
CRGBArray<NUM_LEDS> leds;
void setup() {
Serial.begin(9600);
Serial.println(F("here"));
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(100);
FastLED.clear();
FastLED.show();
delay(1000);
Serial.println(F("here2"));
}
void loop() {
//updatePxArt(16, 16, 8, 0, birdPx);
for (int k = 0; k <= NUM_FRAMES-1; k++){
writeBirdFrame(k);
delay(100);
Serial.println(k);
}
}
void writeBirdFrame(uint8_t frame){
FastLED.clear();
//frames, height(#of 16 px rows), width(16 px), pixels (3 colors)
const PROGMEM uint8_t birdPxf[NUM_FRAMES-1][8][16][3] = {
{{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {239, 127, 68}, {255, 254, 254}, {1, 1, 1}, {254, 254, 252}, {255, 254, 254}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {239, 127, 68}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {254, 254, 252}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {239, 127, 68}, {239, 127, 68}, {239, 127, 68}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {208, 108, 56}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}},
{{{0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {222, 221, 210}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{239, 127, 68}, {239, 127, 68}, {255, 254, 254}, {1, 1, 1}, {254, 254, 252}, {255, 254, 254}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {222, 221, 210}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {254, 254, 252}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}}, {{1, 1, 1}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {239, 127, 68}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}}, {{0, 0, 0}, {209, 108, 56}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{209, 108, 56}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {239, 127, 68}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {209, 108, 56}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}},
{{{0, 0, 0}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{222, 221, 210}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{239, 126, 67}, {255, 254, 254}, {1, 1, 1}, {255, 254, 254}, {255, 254, 254}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {239, 126, 67}}, {{222, 221, 210}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {254, 254, 252}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {0, 0, 0}}, {{222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {239, 126, 67}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {208, 108, 56}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {239, 126, 67}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {239, 126, 67}, {239, 126, 67}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}},
{{{222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}}, {{255, 254, 254}, {1, 1, 1}, {254, 254, 252}, {255, 254, 254}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {239, 127, 68}}, {{255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {254, 254, 252}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {0, 0, 0}, {222, 221, 210}}, {{222, 221, 210}, {222, 221, 210}, {239, 127, 68}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {1, 1, 1}, {222, 221, 210}}, {{0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}}, {{0, 0, 0}, {239, 127, 68}, {239, 127, 68}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {208, 108, 56}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}},
{{{222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}}, {{255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {255, 254, 254}}, {{1, 1, 1}, {255, 254, 254}, {255, 254, 254}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {239, 127, 68}, {255, 254, 254}}, {{255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {254, 254, 252}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {255, 254, 254}}, {{222, 221, 210}, {239, 127, 68}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {222, 221, 210}}, {{0, 0, 0}, {239, 127, 68}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}}, {{239, 127, 68}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {239, 127, 68}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}},
{{{222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {222, 221, 210}}, {{255, 255, 255}, {255, 255, 255}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {255, 255, 255}, {255, 255, 255}}, {{255, 255, 255}, {255, 255, 255}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {239, 127, 68}, {255, 255, 255}, {1, 1, 1}}, {{255, 255, 255}, {255, 255, 255}, {254, 254, 252}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {239, 127, 68}, {255, 255, 255}}, {{239, 127, 68}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {239, 127, 68}, {239, 127, 68}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {208, 108, 56}, {0, 0, 0}}},
{{{222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}}, {{255, 255, 255}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}}, {{255, 255, 255}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {239, 127, 68}, {255, 255, 255}, {1, 1, 1}, {255, 255, 255}}, {{255, 255, 255}, {254, 254, 252}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {239, 127, 68}, {255, 255, 255}, {255, 255, 255}}, {{222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {239, 127, 68}, {239, 127, 68}, {239, 127, 68}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {0, 0, 0}, {208, 108, 56}, {208, 108, 56}, {0, 0, 0}, {0, 0, 0}}},
{{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}}, {{222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}}, {{222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {239, 127, 68}, {255, 254, 254}, {1, 1, 1}, {254, 254, 252}, {255, 254, 254}}, {{254, 254, 252}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}, {255, 254, 254}}, {{222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {239, 127, 68}, {222, 221, 210}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {0, 0, 0}, {239, 127, 68}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {239, 127, 68}, {239, 127, 68}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}},
//{{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {239, 127, 68}, {255, 255, 255}, {1, 1, 1}, {255, 255, 255}, {255, 255, 255}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {0, 0, 0}, {222, 221, 210}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {254, 254, 252}, {222, 221, 210}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {1, 1, 1}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {239, 127, 68}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {208, 108, 56}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {239, 127, 68}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}},
};
const PROGMEM uint8_t lastFramebirdPxf[8][16][3] = {{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {222, 221, 210}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {239, 127, 68}, {255, 255, 255}, {1, 1, 1}, {255, 255, 255}, {255, 255, 255}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {0, 0, 0}, {222, 221, 210}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {255, 255, 255}, {254, 254, 252}, {222, 221, 210}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1}, {1, 1, 1}, {222, 221, 210}, {222, 221, 210}, {222, 221, 210}, {239, 127, 68}, {222, 221, 210}, {222, 221, 210}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {208, 108, 56}, {208, 108, 56}, {0, 0, 0}, {0, 0, 0}, {239, 127, 68}, {239, 127, 68}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}};
if(frame<8){
for (int j = NUM_FRAMES-1; j >= 0; j--){
for (int i = 0; i <= 15; i++) {
leds[XY(i+8, 7-j)] = CRGB ( birdPxf[frame][j][i][0], birdPxf[frame][j][i][1], birdPxf[frame][j][i][2]);
}
}
}
else{
for (int j = 7; j >= 0; j--){
for (int i = 0; i <= 15; i++) {
leds[XY(i+8, 7-j)] = CRGB ( lastFramebirdPxf[j][i][0], lastFramebirdPxf[j][i][1], lastFramebirdPxf[j][i][2]);
}
}
}
FastLED.show();
}
uint16_t XY(uint8_t x, uint8_t y)
{
if(0<=x && x<=31 && 0<=y && y<=15){
uint16_t i;
//check for first or second matrix
//&0x01 checks if odd
bool addAtEnd = false;
if (x>15){
x -= 16;
addAtEnd = true;
}
if(y & 0x01){
// Even rows run backwards
uint8_t reverseX = 15 - x;
uint8_t reverseY = 15 - y;
i = (reverseY * 16) + reverseX;
}
else {
// odd rows run forwards
uint8_t reverseY = 15 - y;
i = (reverseY * 16) + x;
}
if(addAtEnd){
i+=256;
}
/*
Serial.print("x: ");
Serial.print(x);
Serial.print(" y: ");
Serial.print(y);
Serial.print(" i: ");
Serial.println(i);*/
return i;
}
else{
//Serial.println(" bad val");
return NUM_LEDS;
}
}
Here's the poorly made python script that turns the gif into an array that the arduino can use if you're curious.
import cv2
import numpy as np
from PIL import Image
if __name__ == "__main__":
def main():
#input manually
heightPx = 16
widthPx = 16
frames = []
numFrames = 0
with Image.open("Duck2.gif") as im:
im.seek(1) # skip to the second frame
try:
while 1:
im.seek(im.tell() + 1)
data = np.array(im)
for i in range(len(data)):
for j in range(len(data[i])):
data[i][j] = data[i][j][:3]
data = data.tolist()
frames.append(createPxFrame(data))
numFrames+=1
except EOFError:
pass # end of sequence
print(f"uint8_t birdPxf[{numFrames}][{widthPx}][{heightPx}][3] = {{")
for frame in frames:
myStr = str(frame)
myStr = myStr.replace("[","{")
myStr = myStr.replace("]","}")
print(myStr+",")
print("};")
def createPxFrame(data):
newData = []
#Each large pixel is 20 png pixels
for i in range(len(data)):
#320 times for outside of loop with 16 height pixel image
if (i%10 == 0) and (i%20 != 0):
tempData = []
for j in range(len(data[i])):
#640 times for inside of loop with 32 pixel image
if (j%10 == 0) and (j%20 != 0):
tempData.append(data[i][j])
#print(len(tempData))
newData.append(tempData)
#print(len(tempData[:][-1:]))
return newData
main()
Here's the gif in question:
Here's What's currently running on the display (you can see it skip a frame):
I've got some other parts to this project as well (such as multiple arduinos, inputs, and an OLED display communicating over I2C) but they're not connected or being touched in this code.
Probably a good option later on would to be to use an SD card module and store the pixel art on that but I probably should figure out this issue first.