Arduino Sketch mit Bluetooth Modul

Goeggi

Active Member
22 Jul 2016
114
171
#1
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 :smile:
 
Last edited:

St0ne

Honorable
3 Nov 2016
3,348
2,125
#2
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^^
 
Likes: Goeggi

Goeggi

Active Member
22 Jul 2016
114
171
#3
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 :smile:
 
Likes: Radat.

Sephirot

Well-Known Member
2 Jun 2015
1,333
1,030
#4
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.
 
Likes: Goeggi
9 Oct 2015
1,264
3,183
#5
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
}
}
 
Likes: Goeggi

Goeggi

Active Member
22 Jul 2016
114
171
#6
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
 

Goeggi

Active Member
22 Jul 2016
114
171
#8
bau default case ein und schau, ob dieser greift. Dann weißt du, dass dein Problem beim Input liegt.
Habe jetzt anstatt "BluetoothData" var 'a' genommen und als int definiert.
Tisch leuchtet auf, aber nur Standbild wie auch bei den if - Abfragen :frowning:
[doublepost=1522247646,1522236426][/doublepost]So, habs jetzt hinbekommen :smile:
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;
}
 

Goeggi

Active Member
22 Jul 2016
114
171
#9
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 :frowning:

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);
    }
 

Goeggi

Active Member
22 Jul 2016
114
171
#11
Value x 2.55? Als Double halt und dann zu int casten:grin:
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 :smile:
 

Goeggi

Active Member
22 Jul 2016
114
171
#13
Habe es jetzt endlich hinbekommen :smile:

Musste von einem Arduino Uno auf nen Mega switchen, da meine Optimierung so krass ist, dass die 2kB Ram des Uno nicht ausreichen:tearsofjoy:
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 :smile:
 

Hans Sepp

Well-Known Member
18 Feb 2015
981
475
#14
Habe es jetzt endlich hinbekommen :smile:

Musste von einem Arduino Uno auf nen Mega switchen, da meine Optimierung so krass ist, dass die 2kB Ram des Uno nicht ausreichen:tearsofjoy:
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 :smile:
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
 
Likes: Goeggi

Goeggi

Active Member
22 Jul 2016
114
171
#15
Nochmal ne kurze Frage.
Will jetzt mit dem gleichen Prinzip und der App 15m Leds an die Decke schrauben. Der einzige Unterschied ist hierbei, dass ich die Möglichkeit brauche zwischen dem Led Signal des Arduino und eines externen Controllers zu switchen.

Controller:
https://de.aliexpress.com/item/Musi...Led-streifen-DC5-24V-input-k/32678130755.html

Das Ganze habe ich mit einem Relais verwirklicht:
digitalWrite(4, HIGH); => Daten Signal des Arduino wird an die LEDs geschickt
digitalWrite(5, HIGH); => Daten Signal des Externen Controllers wird an die LEDs geschickt

Problem:
Da das Ganze sich in einer While Schleife befindet schaltet das Relais die ganze Zeit, was ziemlich laut ist und das Relais nicht lang überleben wird.


Kurzer Ausschnitt vom Code:
Code:
 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 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if (btData == "b") { // App: "Turn Off - Button" Turns off all LEDs
        Programm = 8;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if (btData == "c") { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation
        Programm = 2 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if  (btData == "d") { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation
        Programm = 3 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if  (btData == "e") { // App: "Dots - Button" Starts the Dots Animation
        Programm = 4 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if  (btData == "f") { // App: "Gradient - Button" Starts the Gradient Animation
        Programm = 5 ;

        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if  (btData == "g") { // App: "Lines - Button" Starts the Lines Animation
        Programm = 6 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if  (btData == "h") { // App: "Random - Button" Starts the Random Animation
        Programm = 7 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if  (btData == "i") { // Switches to external Controller
        Programm = 9 ;
      }
      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);
      }
    }
  }
 
Last edited:

ZeCjy

Honorable
7 Jan 2015
3,246
2,052
#16
Nimm dir nen boolsche variable, und setzt da nen check ein :smile:
Code:
bool external = false;

[...]

while (Programm == 9) {
  if(btData == "i" && !external) {
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
    external = true;
  } else if(btData == "i" && external) {
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
    external = false;
    Programm = 1;
  }
Wenn es jetzt auf Programm = 9 switched, checked er jedes mal ob "i" gesendet wird, und wenn, ob er wechseln muss. (Ich hab jetzt bisschen geraten weil du nur Programm = 1 routine gepostet hast)
btw, haben die meisten Relais nicht auf jeder Seite 3 Pins zwischen denen du switchst?
 
Likes: Goeggi

Goeggi

Active Member
22 Jul 2016
114
171
#17
Nimm dir nen boolsche variable, und setzt da nen check ein :smile:
Code:
bool external = false;

[...]

while (Programm == 9) {
  if(btData == "i" && !external) {
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
    external = true;
  } else if(btData == "i" && external) {
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
    external = false;
    Programm = 1;
  }
Wenn es jetzt auf Programm = 9 switched, checked er jedes mal ob "i" gesendet wird, und wenn, ob er wechseln muss. (Ich hab jetzt bisschen geraten weil du nur Programm = 1 routine gepostet hast)
btw, haben die meisten Relais nicht auf jeder Seite 3 Pins zwischen denen du switchst?
Habs mal mit deiner Möglichkeit probiert aber mache irgendetwas falsch.

Von der App wird nur ein "i" gesendet wenn ich den Button "Use external Controller" drücke.

Mal der ganze Code mit dem Rattern des Relais: (Rattern tritt beim externen Controller nicht auf)

Code:
#include <SoftwareSerial.h>// import the serial library
#include <FastLED.h>
#include <SPI.h>
#include <SD.h>

#define NUM_LEDS 450 // 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;
File CaseG;

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(4, OUTPUT); // Relais 1 - RGB Controller
  pinMode(5, OUTPUT); // Relais 2 - Arduino
  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("rainbow.dat");  // a.dat = Rainbow1 Animation
  CaseB = SD.open("darkrb.dat");  // b.dat = Rainbow2 Animation
  CaseC = SD.open("dots.dat");  // c.dat = Dots Animation
  CaseD = SD.open("fade.dat");  // d.dat = Gradient Animation
  CaseE = SD.open("lines.dat");  // e.dat = Lines Animation
  CaseF = SD.open("mix.dat");  // f.dat = Random Animation
  CaseG = SD.open("sphere.dat");  // g.dat = Darksphere 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 == "i") { // Switches to External Controller
      Programm = 9 ;
    }
    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 == "i") { // Switches to External Controller
        Programm = 9 ;
      }
      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 == "i") { // Switches to External Controller
        Programm = 9 ;
      }
      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 == "i") { // Switches to External Controller
        Programm = 9 ;
      }
      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 == "i") { // Switches to External Controller
        Programm = 9 ;
      }
      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 == "i") { // Switches to External Controller
        Programm = 9 ;
      }
      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 ;
      }
      else if  (btData == "i") { // Switches to External Controller
        Programm = 9 ;
      }
      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);
    CaseG.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 == "i") { // Switches to External Controller
        Programm = 9 ;
      }
      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 == "i") { // Switches to External Controller
        Programm = 9 ;
      }
      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 == 9)
  {
    digitalWrite(5, HIGH);
    digitalWrite(4, LOW);
    if (btSerial.available()) {
      btData = btSerial.readString();
      Serial.print(btData);
      if (btData == "a") { // App: "Turn On - Button" Starts the Random Animation
        Programm = 1 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if (btData == "b") { // App: "Turn Off - Button" Turns off all LEDs
        Programm = 8;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if (btData == "c") { // App: "Rainbow 1 - Button" Starts the Rainbow1 Animation
        Programm = 2 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if  (btData == "d") { // App: "Rainbow 2 - Button" Starts the Rainbow2 Animation
        Programm = 3 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if  (btData == "e") { // App: "Dots - Button" Starts the Dots Animation
        Programm = 4 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if  (btData == "f") { // App: "Gradient - Button" Starts the Gradient Animation
        Programm = 5 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
      else if  (btData == "g") { // App: "Lines - Button" Starts the Lines Animation
        Programm = 6 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);

      }
      else if  (btData == "h") { // App: "Random - Button" Starts the Random Animation
        Programm = 7 ;
        digitalWrite(5, LOW);
        digitalWrite(4, HIGH);
      }
    }
  }
  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();
  CaseG.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;
}
Das Relais Board hat 2 getrennte Relais. 4 Pins: 5V Eingang, GND, Data1, Data2
 

ZeCjy

Honorable
7 Jan 2015
3,246
2,052
#18
Jetzt hast du hier aber was anderes als beim ersten mal gepostet oder?
Wie gesagt, setzt ne variable und schalte das Relais nur einmal, dann setzt die Variable auf den Wert des Relais. Dann checkst du jedes mal wenn du den Wert setzen willst, checkst du ob der Wert gleich ist, dann überspringst du einfach.
 
Likes: Goeggi