Hello,
I am using an Arduino Uno to drive a Neopixel WS8212b LED matrix 16h x 32w reading images from an external SD Card. When I try to compile and load the code, the compiler tells me the dynamic memory has been exceeded:
"Variáveis globais usam 2278 bytes (111%) de memória dinâmica, deixando -230 bytes para
variáveis locais. O máximo são 2048 bytes.
Not enough memory; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing your footprint.
data section exceeds available space in board"
If I reduce the number of LEDs to 256 it does work however it is not enough for my matrix. I have seen lots of examples in the FastLED library that can go beyond the 512 LEDs, not sure my code is heavier due to the SDFat library?
Any ideas how to optimize the code and avoid having to upgrade to Mega ?
Code:
#include <SdFat.h>
#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 512
CRGB leds[NUM_LEDS];
SdFat SD;
int Delay = 19;
// int Delay = 19; //for 33 fps @ 256 leds !!
int bright = 30;
int r = 0;
int b = 0;
int g = 0;
const int chipSelect = 4;
int count = 0;
int lednum = 0;
void setup() {
if (!SD.begin(chipSelect)) {
while (true);
}
LEDS.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
LEDS.setBrightness(bright);
LEDS.clear();
LEDS.show();
delay(Delay);
}
void loop() {
uint8_t buf[192];
File dataFile = SD.open("vidbin.bin");
while (dataFile.available()) {
int n = dataFile.read(buf, sizeof(buf));
for (int i = 0; i < n; i++) {
switch (count) {
case 0:
b = buf[i];
count++;
break;
case 1:
g = buf[i];
count++;
break;
case 2:
r = buf[i];
count = 0;
leds[lednum].setRGB( r, g, b);
lednum++;
if (lednum >= NUM_LEDS) {
FastLED.show();
lednum = 0;
delay(Delay);
}
//wdt_reset();
break;
}
}
}
dataFile.close();
}
Many thanks!!