Hi,
I'm having trouble to get fastLED and SD.h to work togheter. When I run the code with the line FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, ANTALL_LED);
it corrupts my output. If I comment out this line the code runs fine.
Correct output:
initialization done. Fil ok!
And the result with the line is a bunch of squares and questionmarks.
The entire code:
#include <SPI.h>
#include <SD.h>
#include <FastLED.h>
#define ANTALL_LED 300
#define LED_PIN 2
#define CS_PIN 10
File myFile;
CRGB leds[ANTALL_LED];
#define MAX_DATA_LENGTH 50
void setup() {
delay(3000);
Serial.begin(9600);
while (!Serial);
if (!SD.begin(CS_PIN)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
myFile = SD.open("Land.csv");
//FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, ANTALL_LED); //This line makes things weird.
FastLED.setBrightness(10);
char inData[MAX_DATA_LENGTH];
char ID[MAX_DATA_LENGTH];
char Lokasjon[MAX_DATA_LENGTH];
char Farge[MAX_DATA_LENGTH];
if(myFile){Serial.println("Fil ok!");}
else {Serial.println("Fil Problem!");}
while (myFile.available()) {
int index = 0;
char c;
while ((c = myFile.read()) != '\n' && index < MAX_DATA_LENGTH - 1) {
if (c != '\r') {
inData[index++] = c;
}
}
inData[index] = '\0';
char *token = strtok(inData, ";");
int ID = atoi(token);
token = strtok(NULL, ";");
strncpy(Lokasjon, token, MAX_DATA_LENGTH);
token = strtok(NULL, ";");
strncpy(Farge, token, MAX_DATA_LENGTH);
if (strcmp(Farge, "Hvit") == 0){leds[ID] = CRGB::FloralWhite;}
if (strcmp(Farge, "AV") == 0){leds[ID] = CRGB::Black;}
if (strcmp(Farge, "Rod") == 0){leds[ID] = CRGB::Red;}
if (strcmp(Farge, "Gronn") == 0){leds[ID] = CRGB::Green;}
if (strcmp(Farge, "Gul") == 0){leds[ID] = CRGB::Yellow;}
if (strcmp(Farge, "Rosa") == 0){leds[ID] = CRGB::Pink;}
if (strcmp(Farge, "Bla") == 0){leds[ID] = CRGB::Blue;}
if (strcmp(Farge, "Lilla") == 0){leds[ID] = CRGB::Purple;}
if (strcmp(Farge, "Oransje") == 0){leds[ID] = CRGB::Orange;}
}
myFile.close();
FastLED.show();
}
void loop() {}