Sorry, here is the code :
#include <SPI.h>
#include <SD.h>
#include "FastLED.h"
#define NUM_LEDS 240 //LEDs Zahl
#define DATA_PIN 3 //Port von Arduino wo DataIn steht
bool Sd;
byte led; //Zahl der LED, der wird angeschaltet ab jetzt ADR
int Time = 0;
int Demo = 0;
byte sent=0;
byte buff[4];
File Archive;
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); //Initialize FastLED für WS2812B
Serial.begin(250000); //Initialize Serie 9600 Baud
Serial.write('1');
pinMode(4, OUTPUT);
Sd=SD.begin(4);
if (!Sd){ //LED 22 will be RED if the SD card wasnt properly connected, else LED 22 will be green.
leds[22]=CRGB(0,255,0);
FastLED.show();
return;
}
leds[22]=CRGB(255,0,0);FastLED.show();
}
void loop() {
while(Serial.available() < 4){ //Wait until MODE Byte comes
Time++;
delay(1);
if(Time>=10000||Demo==1){ //After 10 seconds waiting starts demo mode, the isn´t 10s delay between Demo modes.
Time=0;
Demo=1;
DEMO();
}
}
Time=0; //Sets the variables to 0, when data stops coming, arduino will wait 10s until starting the Demo mode.
Demo=0;
Serial.readBytes( (byte*)(&buff), 4);
if(buff[0]==240&&buff[2]==220){
SHOW();
}else if (buff[0]==240&&buff[2]==240){
SAVEandSHOW();
}
}
void DEMO(){
leds[19]=CRGB(0,255,0);FastLED.show();
if(Archive != false){
Archive.close();
}
Archive = SD.open("RGB-SD.txt",FILE_READ);
//delay(200);
if (Archive != false){
leds[20]=CRGB(255,0,0);FastLED.show();
while (Archive.available() > 4&&Serial.available() < 4){//&&Serial.available() < 4
leds[20]=CRGB(0,0,0);FastLED.show();
//reads 4 bytes from Archive
Archive.read(buff,4);
leds[buff[0]] = CRGB(buff[1],buff[2],buff[3]);FastLED.show();
leds[20]=CRGB(255,0,0);FastLED.show();
}
leds[20]=CRGB(0,0,0);FastLED.show();
Archive.close();
leds[20]=CRGB(255,0,0);FastLED.show();
}else{
leds[20]=CRGB(0,0,0);FastLED.show();
leds[20]=CRGB(0,255,0);FastLED.show();
}
}
void SAVEandSHOW(){
leds[19]=CRGB(255,0,0);FastLED.show();
if(buff[3]==240){
Archive.close();
//SD.remove((const char *)root.c_str()); //Must use (char *)filename.c_str() to work.
//SD.remove("RGB-SD.TXT");
//SD.remove(filename);
delay(450);
}
if(Archive != false){
Archive.close();
}
//SD.mkdir("A");
Archive = SD.open("RGB-SD.txt",FILE_WRITE);
while(Serial.available() < 4){}
while(buff[2]!=255){//buff[0]!=240&&
while(Serial.available() < 4){}
//Serial.readBytes( (byte*)(&led), 1);
Serial.readBytes( (byte*)(&buff), 4); //Lisst ROT, GRÜN und BLAU und schreibt in led[]
leds[buff[0]]=CRGB(buff[1],buff[2],buff[3]);FastLED.show(); //Anschalt die LED(ADR,ROT,GRÜN,BLAU)
if (Archive != false){
leds[20]=CRGB(255,0,0);FastLED.show();
Archive.write(buff[0]);
Archive.write(buff[1]);
Archive.write(buff[2]);
Archive.write(buff[3]);
leds[20]=CRGB(0,0,0);FastLED.show();
} else {
leds[20]=CRGB(0,0,0);FastLED.show();
leds[20]=CRGB(0,255,0);FastLED.show();
}
}
Archive.close();
}
void SHOW(){
leds[19]=CRGB(0,0,255);FastLED.show();
while(Serial.available() < 4){}
while(buff[2]!=255){//buff[0]!=240&&
while(Serial.available() < 4){}
Serial.readBytes( (byte*)(&buff), 4); //Lisst ROT, GRÜN und BLAU und schreibt in led[]
leds[buff[0]]=CRGB(buff[1],buff[2],buff[3]);FastLED.show(); //Anschalt die LED(ADR,ROT,GRÜN,BLAU)
}
}