#include <SD.h>
#define CS_PIN 5
const uint8_t colCount = 32;
const uint8_t lineCount = 16;
uint32_t ledBuffer[colCount * lineCount];
void setup() {
Serial.begin(115200);
Serial.print("Initializing SD card... ");
if (!SD.begin(CS_PIN)) {
Serial.println("Card initialization failed!");
while (true);
}
Serial.println("initialization done.");
File textFile = SD.open("/Axel.txt");
if (textFile) {
size_t pos = 0;
char buffer[15];
while (textFile.available()) {
if (textFile.readBytesUntil(',', buffer, sizeof buffer) > 0) {
if (pos >= colCount * lineCount) {
Serial.println("too much data input file");
break;
} else {
char * endptr;
ledBuffer[pos++] = strtoul(buffer, &endptr, 16); // could use endptr to detect format error
}
}
}
textFile.close();
if (pos != colCount * lineCount) {
Serial.println("wrong format for input file");
} else {
Serial.println("I read the file.");
for (byte line = 0; line < lineCount; line++) {
for (byte col = 0; col < colCount; col++) {
Serial.printf("0x%06X ", ledBuffer[line * colCount + col], HEX);
}
Serial.println();
}
}
} else {
Serial.println("error opening Axel.txt!");
}
}
void loop() {}