Ok, so here is where im at.
Ive tried declaring frameBuffer[] using PROGMEM.....
char PROGMEM frameBuffer[row][column][maxChars];
The frameBuffer is written to using this line.....
frameBuffer[rowIndex][columnIndex][bufferIndex] = nextChar;
and i'm accessing the PROGMEM frameBuffer array like this.
strcpy_P(buffer, (char*)pgm_read_word(&(frameBuffer[rowCounter][(i / 8)])));
leds[i] = strtoul(buffer, &endptr, 16);
It compiles, but the display is blank. Am i using PROGMEM correctly? Ive seen PROGMEM used before but never used it myself.
Thanks
#include "FS.h"
#include "SD.h"
#include "SPI.h"
#include "FastLED.h"
int rowIndex = 0;
int columnIndex = 0;
int next;
#define NUM_LEDS 512
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
int led;
const byte row = 16;
const byte column = 32;
const byte maxChars = 9;
char PROGMEM frameBuffer[row][column][maxChars];
char buffer[maxChars];
int bufferIndex;
unsigned int readTimer;
void setup() {
Serial.begin(115200);
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(50);
FastLED.clear();
FastLED.show();
delay(2000);
if (!SD.begin()) {
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD.cardType();
if (cardType == CARD_NONE) {
Serial.println("No SD card attached");
return;
}
Serial.print("SD Card Type: ");
if (cardType == CARD_MMC) {
Serial.println("MMC");
} else if (cardType == CARD_SD) {
Serial.println("SDSC");
} else if (cardType == CARD_SDHC) {
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
//readFile(SD, "/Animations/Axel/1.txt");
}
void readFile(fs::FS &fs, const char *path) {
Serial.printf("Reading file: %s\n", path);
File file = fs.open(path);
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
readTimer = millis();
while ((next = file.read()) != -1) {
char nextChar = (char)next;
if (nextChar != 32 && nextChar != '\,' && nextChar != '\n' && nextChar != '\r') {
frameBuffer[rowIndex][columnIndex][bufferIndex] = nextChar;
bufferIndex++;
} else if (nextChar == '\n') {
rowIndex++;
columnIndex = 0;
bufferIndex = 0;
} else if (nextChar == 32) {
columnIndex++;
bufferIndex = 0;
}
}
file.close();
//displayFrame();
}
byte rowCounter = 0;
void displayFrame() {
for (int i = 0; i < 256; i++) {
if (i % 16 > 0 && i % 16 <= 7) {
rowCounter++;
} else if (i % 16 > 8 && i % 16 < 16) {
rowCounter--;
}
char *endptr;
strcpy_P(buffer, (char*)pgm_read_word(&(frameBuffer[rowCounter][(i / 8)])));
leds[i] = strtoul(buffer, &endptr, 16);
}
for (int i = 256; i < 512; i++) {
if (i % 16 > 0 && i % 16 <= 7) {
rowCounter++;
} else if (i % 16 > 8 && i % 16 < 16) {
rowCounter--;
}
char *endptr;
strcpy_P(buffer, (char*)pgm_read_word(&(frameBuffer[rowCounter + 8][i / 8 - 32])));
leds[i] = strtoul(buffer, &endptr, 16);
}
FastLED.show();
for (int i = 0; i < row; i++) {
for (int k = 0; k < column; k++) {
Serial.print(frameBuffer[i][k]);
Serial.print(", ");
}
Serial.println();
}
}
byte i = 0;
unsigned long frameTimer;
int frameLength = 500;
char *animations[3] = { "/Animations/Axel/1.txt", "/Animations/Axel/2.txt", "/Animations/Axel/3.txt" };
void loop() {
if (millis() - frameTimer > frameLength) {
if (i == 0) {
readFile(SD, animations[0]);
delay(50);
displayFrame();
}
if (i == 1) {
readFile(SD, animations[1]);
delay(50);
displayFrame();
}
if (i == 2) {
readFile(SD, animations[2]);
delay(50);
displayFrame();
i == 0;
}
i++;
frameTimer = millis();
}
}