Hey, baue gerade in meinen LED Tisch App Support ein. LED Tisch: Die App sendet einen Textbaustein zu dem Arduino HC-05 Bluetooth Modul. Entweder "a,b,c,d,e,f" Wobei jeder Buchstabe für eine andere Animation steht. Code: #include <SoftwareSerial.h>// import the serial library #include <FastLED.h> #include <SPI.h> #include <SD.h> #define NUM_LEDS 100 // LED number #define DATA_PIN 3 //LED data pin #define CHIPSET WS2812B //LED type #define CMD_NEW_DATA 1 int brightness = 255; // Brightness int speed = 50; // Speed int BluetoothData; // Bluetooth Received Data unsigned char x = 10; // matrix x size unsigned char y = 10; // matrix y size File CaseA; File CaseB; File CaseC; File CaseD; File CaseE; File CaseF; CRGB leds[NUM_LEDS]; SoftwareSerial BTSerial(5, 6); // RX, TX (Bluetooth Module) void setup() { FastLED.addLeds<CHIPSET, DATA_PIN, GRB>(leds, NUM_LEDS); Serial.begin(1152000); BTSerial.begin(9600); for (int y = 0 ; y < NUM_LEDS ; y++) { leds[y] = CRGB::Black; // set all leds to black during setup } FastLED.show(); pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work. digitalWrite(10, HIGH); // workaround for sdcard failed error... (!SD.begin(4)); } void loop() { CaseA = SD.open("a.dat"); // a.dat = Rainbow1 Animation CaseB = SD.open("b.dat"); // b.dat = Rainbow2 Animation CaseC = SD.open("c.dat"); // c.dat = Dots Animation CaseD = SD.open("d.dat"); // d.dat = Gradient Animation CaseE = SD.open("e.dat"); // e.dat = Lines Animation CaseF = SD.open("f.dat"); // f.dat = Random Animation if (BTSerial.available()) { BluetoothData = BTSerial.read(); if (BluetoothData == 'a') { // App: "Turn On - Button" Starts the Random Animation CaseF.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); //1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right) FastLED.setBrightness(brightness); FastLED.show(); delay(speed); // set the speed of the animation. 20 is appx ~ 500k bauds } if (BluetoothData == 'b') { // App: "Turn Off - Button" Turns off all LEDs FastLED.clear(); FastLED.show(); } if (BluetoothData == 'c') { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation CaseA.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } if (BluetoothData == 'd') { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation CaseB.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } if (BluetoothData == 'e') { // App: "Dots - Button" Starts the Dots Animation CaseC.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } if (BluetoothData == 'f') { // App: "Gradient - Button" Starts the Gradient Animation CaseD.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } if (BluetoothData == 'g') { // App: "Lines - Button" Starts the Lines Animation CaseE.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } if (BluetoothData == 'h') { // App: "Random - Button" Starts the Random Animation CaseF.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } } CaseA.close(); // close the file in order to prevent hanging IO or similar throughout time CaseB.close(); CaseC.close(); CaseD.close(); CaseE.close(); CaseF.close(); } int ledSort (int modus) { //1=TL,2=TR,3=BL,4=BR, this function will rearrange the led array CRGB tmp[x]; if (modus == 3 || modus == 4) { for (int i = 0; i < (y / 1); i++) { for (int j = 0; j < x; j++) { tmp[j] = leds[i * x + j]; leds[i * x] = leds[(y - i - 1) * x]; leds[(y - i - 1) * x] = tmp[j]; } } } return 1; } Habe den Code mal bisschen aufgeräumt und besser kommentiert. Kann jetzt die verschiedenen Animationen in der App auswählen. Das Problem ist, dass nur das erste Frame der Animation gezeigt wird (Standbild). Liegt vermutlich an dem "if", denn mit einer while Schleife geht es. Wegen der while Schleife kann ich aber nicht die Animation wechseln weil der Input der App ja nur einmal geprüft wird und die Animation dann durchläuft. Dass ihr seht was ich meine: (Ja, ich hab immer noch das hässliche Sofa xD) Brauche als einen Weg um aus der while Schleife zu kommen. Hat wer ne Idee wie ich das mache oder eine bessere Lösung? Danke euch schonmal
Habe als Abschlussprüfung von der Schule damals auch was mit Arduino + HC-05 gemacht. Wenn ich mich recht erinnere muss man doch den RX und den TX Pin vom Bluetooth Modul festlegen, kann morgen mal in die Sketche von damals reinschauen. Ging glaube ich mit define, kann Arduino nicht wirklich auswendig, habe damals größtenteils copy-pasted^^
Code: #include <SoftwareSerial.h>// import the serial library #include <FastLED.h> #include <SPI.h> #include <SD.h> #define NUM_LEDS 100 // LED number #define DATA_PIN 3 //LED data pin #define CHIPSET WS2812B //LED type #define CMD_NEW_DATA 1 int brightness = 255; // Brightness int speed = 50; // Speed int BluetoothData; // Bluetooth Received Data unsigned char x = 10; // matrix x size unsigned char y = 10; // matrix y size File CaseA; File CaseB; File CaseC; File CaseD; File CaseE; File CaseF; CRGB leds[NUM_LEDS]; SoftwareSerial BTSerial(5, 6); // RX, TX (Bluetooth Module) void setup() { FastLED.addLeds<CHIPSET, DATA_PIN, GRB>(leds, NUM_LEDS); Serial.begin(1152000); BTSerial.begin(9600); for (int y = 0 ; y < NUM_LEDS ; y++) { leds[y] = CRGB::Black; // set all leds to black during setup } FastLED.show(); pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work. digitalWrite(10, HIGH); // workaround for sdcard failed error... (!SD.begin(4)); } void loop() { CaseA = SD.open("a.dat"); // a.dat = Rainbow1 Animation CaseB = SD.open("b.dat"); // b.dat = Rainbow2 Animation CaseC = SD.open("c.dat"); // c.dat = Dots Animation CaseD = SD.open("d.dat"); // d.dat = Gradient Animation CaseE = SD.open("e.dat"); // e.dat = Lines Animation CaseF = SD.open("f.dat"); // f.dat = Random Animation if (BTSerial.available()) { BluetoothData = BTSerial.read(); if (BluetoothData == 'a') { // App: "Turn On - Button" Starts the Random Animation CaseF.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); //1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right) FastLED.setBrightness(brightness); FastLED.show(); delay(speed); // set the speed of the animation. 20 is appx ~ 500k bauds } if (BluetoothData == 'b') { // App: "Turn Off - Button" Turns off all LEDs FastLED.clear(); FastLED.show(); } if (BluetoothData == 'c') { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation CaseA.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } if (BluetoothData == 'd') { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation CaseB.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } if (BluetoothData == 'e') { // App: "Dots - Button" Starts the Dots Animation CaseC.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } if (BluetoothData == 'f') { // App: "Gradient - Button" Starts the Gradient Animation CaseD.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } if (BluetoothData == 'g') { // App: "Lines - Button" Starts the Lines Animation CaseE.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } if (BluetoothData == 'h') { // App: "Random - Button" Starts the Random Animation CaseF.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); } } CaseA.close(); // close the file in order to prevent hanging IO or similar throughout time CaseB.close(); CaseC.close(); CaseD.close(); CaseE.close(); CaseF.close(); } int ledSort (int modus) { //1=TL,2=TR,3=BL,4=BR, this function will rearrange the led array CRGB tmp[x]; if (modus == 3 || modus == 4) { for (int i = 0; i < (y / 1); i++) { for (int j = 0; j < x; j++) { tmp[j] = leds[i * x + j]; leds[i * x] = leds[(y - i - 1) * x]; leds[(y - i - 1) * x] = tmp[j]; } } } return 1; } Habe den Code mal bisschen aufgeräumt und besser kommentiert. Kann jetzt die verschiedenen Animationen in der App auswählen. Das Problem ist, dass nur das erste Frame der Animation gezeigt wird (Standbild). Liegt vermutlich an dem "if", denn mit einer while Schleife geht es. Wegen der while Schleife kann ich aber nicht die Animation wechseln weil der Input der App ja nur einmal geprüft wird und die Animation dann durchläuft. Dass ihr seht was ich meine: (Ja, ich hab immer noch das hässliche Sofa xD) Brauche als einen Weg um aus der while Schleife zu kommen. Hat wer ne Idee wie ich das mache oder eine bessere Lösung? Danke euch schonmal
Habe jetzt mir den Code nicht durchgehend angeschaut, verstehe aber deine Problem. Wenn ich sowas programmieren würde, würde ich mir eine Globale Variable deklarieren, die den State präsentiert und dann in einer einer While-Schleife ein Switch-Case programmieren und je nach State vorfahren. Kannst ja vordem switch-case eine Methode callen, die nachschaut, ob es ich was geändert hat und somit den State ändern. Falls ich nicht richtig gelesen habe und das Problem falsch verstanden habe, sorry. Bin bissel drunk.
Statt die ganze Animation von dem Input abhängig zu machen, mach ne while loop in der du erst den Input checks und dann egal was ist, die Animation spielst (default case für off oder w/e) Pseudo Code: while(true) { if (BTSerial.available()) BluetoothData = BTSerial.read(); switch(BluetoothData) { //Dein Switchcase } }
Habs jetzt mal mit folgendem Code ausprobiert, der Tisch bleibt jedoch dunkel: Code: #include <SoftwareSerial.h>// import the serial library #include <FastLED.h> #include <SPI.h> #include <SD.h> #define NUM_LEDS 100 // LED number #define DATA_PIN 3 //LED data pin #define CHIPSET WS2812B //LED type #define CMD_NEW_DATA 1 int brightness = 255; // Brightness int speed = 50; // Speed int BluetoothData; // Bluetooth Received Data unsigned char x = 10; // matrix x size unsigned char y = 10; // matrix y size File CaseA; File CaseB; File CaseC; File CaseD; File CaseE; File CaseF; CRGB leds[NUM_LEDS]; SoftwareSerial BTSerial(5, 6); // RX, TX (Bluetooth Module) void setup() { FastLED.addLeds<CHIPSET, DATA_PIN, GRB>(leds, NUM_LEDS); Serial.begin(115200); BTSerial.begin(9600); for (int y = 0 ; y < NUM_LEDS ; y++) { leds[y] = CRGB::Black; // set all leds to black during setup } FastLED.show(); pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work. digitalWrite(10, HIGH); // workaround for sdcard failed error... (!SD.begin(4)); } void loop() { CaseA = SD.open("a.dat"); // a.dat = Rainbow1 Animation CaseB = SD.open("b.dat"); // b.dat = Rainbow2 Animation CaseC = SD.open("c.dat"); // c.dat = Dots Animation CaseD = SD.open("d.dat"); // d.dat = Gradient Animation CaseE = SD.open("e.dat"); // e.dat = Lines Animation CaseF = SD.open("f.dat"); // f.dat = Random Animation while (true) { if (BTSerial.available()) int BluetoothData = BTSerial.read(); Serial.print(BluetoothData); switch (BluetoothData) { case 'a': // App: "Turn On - Button" Starts the Random Animation CaseF.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); //1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right) FastLED.setBrightness(brightness); FastLED.show(); delay(speed); // set the speed of the animation. 20 is appx ~ 500k bauds break; case 'b': // App: "Turn Off - Button" Turns off all LEDs FastLED.clear(); FastLED.show(); break; case 'c': // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation CaseA.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); break; case 'd': // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation CaseB.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); break; case 'e': // App: "Dots - Button" Starts the Dots Animation CaseC.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); break; case 'f': // App: "Gradient - Button" Starts the Gradient Animation CaseD.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); break; case 'g': // App: "Lines - Button" Starts the Lines Animation CaseE.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); break; case 'h': // App: "Random - Button" Starts the Random Animation CaseF.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); break; } CaseA.close(); // close the file in order to prevent hanging IO or similar throughout time CaseB.close(); CaseC.close(); CaseD.close(); CaseE.close(); CaseF.close(); } } int ledSort (int modus) { //1=TL,2=TR,3=BL,4=BR, this function will rearrange the led array CRGB tmp[x]; if (modus == 3 || modus == 4) { for (int i = 0; i < (y / 1); i++) { for (int j = 0; j < x; j++) { tmp[j] = leds[i * x + j]; leds[i * x] = leds[(y - i - 1) * x]; leds[(y - i - 1) * x] = tmp[j]; } } } return 1; } Sehe meinen Fehler gerade nicht
Habe jetzt anstatt "BluetoothData" var 'a' genommen und als int definiert. Tisch leuchtet auf, aber nur Standbild wie auch bei den if - Abfragen --- Double Post Merged, 28 Mar 2018, Original Post Date: 28 Mar 2018 --- So, habs jetzt hinbekommen Der Code ist zwar richtig unschön und man hätte es bestimmt auch mit weniger Code machen können. Aber man siehts dem Arduino ja nicht an xD Werde noch eine Option für Helligkeit und Geschwindigkeit einfügen. Hier der funktionierende Code: Code: #include <SoftwareSerial.h>// import the serial library #include <FastLED.h> #include <SPI.h> #include <SD.h> #define NUM_LEDS 100 // LED number #define DATA_PIN 3 //LED data pin #define CHIPSET WS2812B //LED type #define CMD_NEW_DATA 1 int brightness = 255; // Brightness int speed = 50; // Speed int BluetoothData; // Bluetooth Received Data unsigned char x = 10; // matrix x size unsigned char y = 10; // matrix y size byte Programm = 0 ; //TFT File CaseA; File CaseB; File CaseC; File CaseD; File CaseE; File CaseF; CRGB leds[NUM_LEDS]; SoftwareSerial BTSerial(5, 6); // RX, TX (Bluetooth Module) void setup() { FastLED.addLeds<CHIPSET, DATA_PIN, GRB>(leds, NUM_LEDS); Serial.begin(115200); BTSerial.begin(9600); for (int y = 0 ; y < NUM_LEDS ; y++) { leds[y] = CRGB::Black; // set all leds to black during setup } FastLED.show(); pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work. digitalWrite(10, HIGH); // workaround for sdcard failed error... (!SD.begin(4)); } void loop() { CaseA = SD.open("a.dat"); // a.dat = Rainbow1 Animation CaseB = SD.open("b.dat"); // b.dat = Rainbow2 Animation CaseC = SD.open("c.dat"); // c.dat = Dots Animation CaseD = SD.open("d.dat"); // d.dat = Gradient Animation CaseE = SD.open("e.dat"); // e.dat = Lines Animation CaseF = SD.open("f.dat"); // f.dat = Random Animation if (BTSerial.available()) { BluetoothData = BTSerial.read(); delay(20); if (BluetoothData == 'a') { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } if (BluetoothData == 'b') { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } if (BluetoothData == 'c') { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } if (BluetoothData == 'd') { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } if (BluetoothData == 'e') { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } if (BluetoothData == 'f') { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } if (BluetoothData == 'g') { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } if (BluetoothData == 'h') { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } } while (Programm == 1) { CaseF.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); //1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right) FastLED.setBrightness(brightness); FastLED.show(); delay(speed); // set the speed of the animation. 20 is appx ~ 500k bauds BluetoothData = BTSerial.read(); if (BluetoothData == 'a') { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } if (BluetoothData == 'b') { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } if (BluetoothData == 'c') { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } if (BluetoothData == 'd') { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } if (BluetoothData == 'e') { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } if (BluetoothData == 'f') { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } if (BluetoothData == 'g') { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } if (BluetoothData == 'h') { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } } while (Programm == 2) { CaseA.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); BluetoothData = BTSerial.read(); if (BluetoothData == 'a') { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } if (BluetoothData == 'b') { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } if (BluetoothData == 'c') { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } if (BluetoothData == 'd') { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } if (BluetoothData == 'e') { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } if (BluetoothData == 'f') { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } if (BluetoothData == 'g') { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } if (BluetoothData == 'h') { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } } while (Programm == 3) { CaseB.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); BluetoothData = BTSerial.read(); if (BluetoothData == 'a') { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } if (BluetoothData == 'b') { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } if (BluetoothData == 'c') { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } if (BluetoothData == 'd') { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } if (BluetoothData == 'e') { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } if (BluetoothData == 'f') { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } if (BluetoothData == 'g') { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } if (BluetoothData == 'h') { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } } while (Programm == 4) { CaseC.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); BluetoothData = BTSerial.read(); if (BluetoothData == 'a') { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } if (BluetoothData == 'b') { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } if (BluetoothData == 'c') { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } if (BluetoothData == 'd') { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } if (BluetoothData == 'e') { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } if (BluetoothData == 'f') { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } if (BluetoothData == 'g') { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } if (BluetoothData == 'h') { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } } while (Programm == 5) { CaseD.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); BluetoothData = BTSerial.read(); if (BluetoothData == 'a') { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } if (BluetoothData == 'b') { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } if (BluetoothData == 'c') { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } if (BluetoothData == 'd') { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } if (BluetoothData == 'e') { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } if (BluetoothData == 'f') { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } if (BluetoothData == 'g') { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } if (BluetoothData == 'h') { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } } while (Programm == 6) { CaseE.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); BluetoothData = BTSerial.read(); if (BluetoothData == 'a') { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } if (BluetoothData == 'b') { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } if (BluetoothData == 'c') { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } if (BluetoothData == 'd') { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } if (BluetoothData == 'e') { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } if (BluetoothData == 'f') { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } if (BluetoothData == 'g') { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } if (BluetoothData == 'h') { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } } while (Programm == 7) { CaseF.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); BluetoothData = BTSerial.read(); if (BluetoothData == 'a') { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } if (BluetoothData == 'b') { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } if (BluetoothData == 'c') { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } if (BluetoothData == 'd') { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } if (BluetoothData == 'e') { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } if (BluetoothData == 'f') { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } if (BluetoothData == 'g') { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } if (BluetoothData == 'h') { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } } while (Programm == 8) { FastLED.clear(); FastLED.show(); BluetoothData = BTSerial.read(); if (BluetoothData == 'a') { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } if (BluetoothData == 'b') { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } if (BluetoothData == 'c') { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } if (BluetoothData == 'd') { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } if (BluetoothData == 'e') { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } if (BluetoothData == 'f') { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } if (BluetoothData == 'g') { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } if (BluetoothData == 'h') { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } } CaseA.close(); // close the file in order to prevent hanging IO or similar throughout time CaseB.close(); CaseC.close(); CaseD.close(); CaseE.close(); CaseF.close(); } int ledSort (int modus) { //1=TL,2=TR,3=BL,4=BR, this function will rearrange the led array CRGB tmp[x]; if (modus == 3 || modus == 4) { for (int i = 0; i < (y / 1); i++) { for (int j = 0; j < x; j++) { tmp[j] = leds[i * x + j]; leds[i * x] = leds[(y - i - 1) * x]; leds[(y - i - 1) * x] = tmp[j]; } } } return 1; }
Ich habe mich jetzt noch an die Helligkeitssteuerung ran gewagt. In der App habe ich einen Slider, die eine "3" (zum erkennen, dass es ein Helligkeitswert ist) und dann die Value 0 - 100 ausgeben kann. Der Code geht auch so weit. Das Problem ist, dass in der FastLED Library die Value 0-255 möglich ist. Wenn ich in der App den Slider dann auf 100% setze, setzt der Arduino diese auch auf 100, was weniger als die Hälfte der möglichen Helligkeit ist. Ich müsste den Wert also umrechnen und habe keine Idee wie ich das anstellen soll Hier mein Code zur Helligkeitssteuerung: Code: if (btData.startsWith("3")) { String stringBrightness = btData.substring(btData.indexOf("3") + 1, btData.length()); brightness = stringBrightness.toInt(); FastLED.setBrightness(brightness); }
Danke hat geklappt. Habe jetzt das Gleiche noch mit der Geschwindigkeit vor. Die App gibt eine "4" (zum erkennen, dass es ein Geschwindigkeitswert ist) und dann die Value 0 - 100 aus. Im Arduino soll dabei ein delay entstehen. Dies klappt auch. Momentan ist es aber so, dass wenn in der App der Slider auf 100 steht das delay im Arduino auch 100 ist. Es soll aber so sein, dass: Slider 0% = delay 200 Slider 100% = delay 0 Also genau umgekehrt. Mein Code bisher: Code: if (btData.startsWith("4")) { String stringSpeed = btData.substring(btData.indexOf("4") + 1, btData.length()); speedd = stringSpeed.toInt(); speed = speedd*2; delay(speed); } Hat wer eine Idee wie ich das umrechnen kann. Danke euch schonmal
Habe es jetzt endlich hinbekommen Musste von einem Arduino Uno auf nen Mega switchen, da meine Optimierung so krass ist, dass die 2kB Ram des Uno nicht ausreichen Mit den 8kB Ram vom Mega läufts jetzt endlich flüssig und das switchen zwischen den Animation läuft jetzt auch flotter. Hier der fertige Code: Code: #include <SoftwareSerial.h>// import the serial library #include <FastLED.h> #include <SPI.h> #include <SD.h> #define NUM_LEDS 100 // LED number #define DATA_PIN 3 //LED data pin #define CHIPSET WS2812B //LED type #define CMD_NEW_DATA 1 int brightness = 255; // Brightness int brightnesss; int speed = 50; // Speed int speedd; int btw; String btData; // Bluetooth Received Data String stringBrightness; String stringSpeed; unsigned char x = 10; // matrix x size unsigned char y = 10; // matrix y size byte Programm = 0 ; //TFT File CaseA; File CaseB; File CaseC; File CaseD; File CaseE; File CaseF; CRGB leds[NUM_LEDS]; SoftwareSerial btSerial(62, 11); // RX, TX (Bluetooth Module) void setup() { FastLED.addLeds<CHIPSET, DATA_PIN, GRB>(leds, NUM_LEDS); Serial.begin(115200); btSerial.begin(9600); Serial.print("bluetooth available"); for (int y = 0 ; y < NUM_LEDS ; y++) { leds[y] = CRGB::Black; // set all leds to black during setup } FastLED.show(); pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work. digitalWrite(10, HIGH); // workaround for sdcard failed error... (!SD.begin(4)); } void loop() { CaseA = SD.open("rbone.dat"); // a.dat = Rainbow1 Animation CaseB = SD.open("rbtwo.dat"); // b.dat = Rainbow2 Animation CaseC = SD.open("dots.dat"); // c.dat = Dots Animation CaseD = SD.open("gradient.dat"); // d.dat = Gradient Animation CaseE = SD.open("lines.dat"); // e.dat = Lines Animation CaseF = SD.open("random.dat"); // f.dat = Random Animation if (btSerial.available()) { btData = btSerial.readString(); Serial.print(btData); if (btData == "a") { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } else if (btData == "b") { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } else if (btData == "c") { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } else if (btData == "d") { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } else if (btData == "e") { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } else if (btData == "f") { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } else if (btData == "g") { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } else if (btData == "h") { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } else if (btData.startsWith("3")) { String stringBrightness = btData.substring(btData.indexOf("3") + 1, btData.length()); brightnesss = stringBrightness.toInt(); brightness = brightnesss * 2.55; FastLED.setBrightness(brightness); } else if (btData.startsWith("4")) { String stringSpeed = btData.substring(btData.indexOf("4") + 1, btData.length()); speedd = stringSpeed.toInt(); btw = speedd * 2; speed = 200 - btw; delay(speed); } } while (Programm == 1) { Serial.print(btData); CaseF.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); if (btSerial.available()) { btData = btSerial.readString(); Serial.print(btData); if (btData == "a") { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } else if (btData == "b") { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } else if (btData == "c") { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } else if (btData == "d") { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } else if (btData == "e") { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } else if (btData == "f") { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } else if (btData == "g") { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } else if (btData == "h") { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } else if (btData.startsWith("3")) { String stringBrightness = btData.substring(btData.indexOf("3") + 1, btData.length()); brightnesss = stringBrightness.toInt(); brightness = brightnesss * 2.55; FastLED.setBrightness(brightness); } else if (btData.startsWith("4")) { String stringSpeed = btData.substring(btData.indexOf("4") + 1, btData.length()); speedd = stringSpeed.toInt(); btw = speedd * 2; speed = 200 - btw; delay(speed); } } } while (Programm == 2) { Serial.print(btData); CaseA.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); if (btSerial.available()) { btData = btSerial.readString(); Serial.print(btData); if (btData == "a") { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } else if (btData == "b") { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } else if (btData == "c") { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } else if (btData == "d") { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } else if (btData == "e") { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } else if (btData == "f") { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } else if (btData == "g") { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } else if (btData == "h") { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } else if (btData.startsWith("3")) { String stringBrightness = btData.substring(btData.indexOf("3") + 1, btData.length()); brightnesss = stringBrightness.toInt(); brightness = brightnesss * 2.55; FastLED.setBrightness(brightness); } else if (btData.startsWith("4")) { String stringSpeed = btData.substring(btData.indexOf("4") + 1, btData.length()); speedd = stringSpeed.toInt(); btw = speedd * 2; speed = 200 - btw; delay(speed); } } } while (Programm == 3) { Serial.print(btData); CaseB.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); if (btSerial.available()) { btData = btSerial.readString(); Serial.print(btData); if (btData == "a") { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } else if (btData == "b") { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } else if (btData == "c") { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } else if (btData == "d") { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } else if (btData == "e") { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } else if (btData == "f") { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } else if (btData == "g") { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } else if (btData == "h") { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } else if (btData.startsWith("3")) { String stringBrightness = btData.substring(btData.indexOf("3") + 1, btData.length()); brightnesss = stringBrightness.toInt(); brightness = brightnesss * 2.55; FastLED.setBrightness(brightness); } else if (btData.startsWith("4")) { String stringSpeed = btData.substring(btData.indexOf("4") + 1, btData.length()); speedd = stringSpeed.toInt(); btw = speedd * 2; speed = 200 - btw; delay(speed); } } } while (Programm == 4) { Serial.print(btData); CaseC.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); if (btSerial.available()) { btData = btSerial.readString(); Serial.print(btData); if (btData == "a") { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } else if (btData == "b") { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } else if (btData == "c") { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } else if (btData == "d") { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } else if (btData == "e") { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } else if (btData == "f") { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } else if (btData == "g") { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } else if (btData == "h") { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } else if (btData.startsWith("3")) { String stringBrightness = btData.substring(btData.indexOf("3") + 1, btData.length()); brightnesss = stringBrightness.toInt(); brightness = brightnesss * 2.55; FastLED.setBrightness(brightness); } else if (btData.startsWith("4")) { String stringSpeed = btData.substring(btData.indexOf("4") + 1, btData.length()); speedd = stringSpeed.toInt(); btw = speedd * 2; speed = 200 - btw; delay(speed); } } } while (Programm == 5) { Serial.print(btData); CaseD.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); if (btSerial.available()) { btData = btSerial.readString(); Serial.print(btData); if (btData == "a") { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } else if (btData == "b") { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } else if (btData == "c") { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } else if (btData == "d") { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } else if (btData == "e") { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } else if (btData == "f") { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } else if (btData == "g") { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } else if (btData == "h") { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } else if (btData.startsWith("3")) { String stringBrightness = btData.substring(btData.indexOf("3") + 1, btData.length()); brightnesss = stringBrightness.toInt(); brightness = brightnesss * 2.55; FastLED.setBrightness(brightness); } else if (btData.startsWith("4")) { String stringSpeed = btData.substring(btData.indexOf("4") + 1, btData.length()); speedd = stringSpeed.toInt(); btw = speedd * 2; speed = 200 - btw; delay(speed); } } } while (Programm == 6) { Serial.print(btData); CaseE.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); if (btSerial.available()) { btData = btSerial.readString(); Serial.print(btData); if (btData == "a") { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } else if (btData == "b") { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } else if (btData == "c") { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } else if (btData == "d") { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } else if (btData == "e") { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } else if (btData == "f") { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } else if (btData == "g") { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } else if (btData == "h") { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } if (btData.startsWith("3")) { String stringBrightness = btData.substring(btData.indexOf("3") + 1, btData.length()); brightnesss = stringBrightness.toInt(); brightness = brightnesss * 2.55; FastLED.setBrightness(brightness); } if (btData.startsWith("4")) { String stringSpeed = btData.substring(btData.indexOf("4") + 1, btData.length()); speedd = stringSpeed.toInt(); btw = speedd * 2; speed = 200 - btw; delay(speed); } } } while (Programm == 7) { Serial.print(btData); CaseF.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(brightness); FastLED.show(); delay(speed); if (btSerial.available()) { btData = btSerial.readString(); Serial.print(btData); if (btData == "a") { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } else if (btData == "b") { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } else if (btData == "c") { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } else if (btData == "d") { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } else if (btData == "e") { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } else if (btData == "f") { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } else if (btData == "g") { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } else if (btData == "h") { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } else if (btData.startsWith("3")) { String stringBrightness = btData.substring(btData.indexOf("3") + 1, btData.length()); brightnesss = stringBrightness.toInt(); brightness = brightnesss * 2.55; FastLED.setBrightness(brightness); } else if (btData.startsWith("4")) { String stringSpeed = btData.substring(btData.indexOf("4") + 1, btData.length()); speedd = stringSpeed.toInt(); btw = speedd * 2; speed = 200 - btw; delay(speed); } } } while (Programm == 8) { Serial.print(btData); CaseB.readBytes((char*)leds, NUM_LEDS * 3); ledSort(1); FastLED.setBrightness(0); FastLED.show(); delay(speed); if (btSerial.available()) { btData = btSerial.readString(); Serial.print(btData); if (btData == "a") { // App: "Turn On - Button" Starts the Random Animation Programm = 1 ; } else if (btData == "b") { // App: "Turn Off - Button" Turns off all LEDs Programm = 8; } else if (btData == "c") { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation Programm = 2 ; } else if (btData == "d") { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation Programm = 3 ; } else if (btData == "e") { // App: "Dots - Button" Starts the Dots Animation Programm = 4 ; } else if (btData == "f") { // App: "Gradient - Button" Starts the Gradient Animation Programm = 5 ; } else if (btData == "g") { // App: "Lines - Button" Starts the Lines Animation Programm = 6 ; } else if (btData == "h") { // App: "Random - Button" Starts the Random Animation Programm = 7 ; } else if (btData.startsWith("4")) { String stringSpeed = btData.substring(btData.indexOf("4") + 1, btData.length()); speedd = stringSpeed.toInt(); btw = speedd * 2; speed = 200 - btw; delay(speed); } } } CaseA.close(); // close the file in order to prevent hanging IO or similar throughout time CaseB.close(); CaseC.close(); CaseD.close(); CaseE.close(); CaseF.close(); } int ledSort (int modus) { //1=TL,2=TR,3=BL,4=BR, this function will rearrange the led array CRGB tmp[x]; if (modus == 3 || modus == 4) { for (int i = 0; i < (y / 1); i++) { for (int j = 0; j < x; j++) { tmp[j] = leds[i * x + j]; leds[i * x] = leds[(y - i - 1) * x]; leds[(y - i - 1) * x] = tmp[j]; } } } return 1; } Zur Veraunschaulichung noch ein kleines Video: Danke an alle die mir geholfen haben
Hab mir Code bisschen angeglubscht, und könntest glaub ich einiges an kb sparen wenn du nicht die while loop 3x pasten würdest, sondern einfach if(Programm == x) in einer loop machen würdest ;x