Arduino Sketch mit Bluetooth Modul

Kraisie

Active Member
1 Apr 2017
88
130
#23
Zumindest in C ist es so, dass 0 = false und alles andere, also 1,2,3 etc. true ist (auch negative Zahlen). In C gibt es zwar _Bool, aber true und false sind keine regulären Ausdrücke für diese Sprache. Man müsste beispielsweise stdbool includen, oder vorher definieren was true und was false sein soll.
Da das hier C++ ist kann man natürlich true und false verwenden, aber letztendlich könnte man das ganze auch in einem Bit speichern (zumindest in C, ich kenne mich in C++ nicht sonderlich aus).
Ich denke, dass die Verwirrung daher kommt, dass true oder false am Ende im Speicher eh 0, oder 1 ist und man somit auch direkt 0 und 1 nutzen kann, wobei ich persönlich true und false leserlicher finde.
 

Goeggi

Active Member
22 Jul 2016
114
172
#24
Ich kriegs gerade einfach nicht hin. Habs mit der external Variable probiert aber es klackert immer noch vor sich hin.
Vllt ist es nur ein kleiner Fehler oder ich hab nicht gerafft wie ich das einsetzen muss.
Das Rattern tritt nur auf, wenn der Arduino selber die LEDs ansteuert.

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;
bool external = false;


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
  external = false;
  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)
  {
    external = true;
    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" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 1 ;
      }
      else if (btData == "a" && external)  { // Switches to External Controller
        Programm = 1 ;
      }
      else if (btData == "b" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 8 ;
      }
      else if (btData == "b" && external)  { // Switches to External Controller
        Programm = 8 ;
      }
      else if (btData == "c" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 2 ;
      }
      else if (btData == "c" && external)  { // Switches to External Controller
        Programm = 2 ;
      }
      else if (btData == "d" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 3 ;
      }
      else if (btData == "d" && external)  { // Switches to External Controller
        Programm = 3 ;
      }
      else if (btData == "e" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 4 ;
      }
      else if (btData == "e" && external)  { // Switches to External Controller
        Programm = 4 ;
      }
      else if (btData == "f" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 5 ;
      }
      else if (btData == "f" && external)  { // Switches to External Controller
        Programm = 5 ;
      }
      else if (btData == "g" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 6 ;
      }
      else if (btData == "g" && external)  { // Switches to External Controller
        Programm = 6 ;
      }
      else if (btData == "h" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 7 ;
      }
      else if (btData == "h" && external)  { // Switches to External Controller
        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)
  {
    external = true;
    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" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 1 ;
      }
      else if (btData == "a" && external)  { // Switches to External Controller
        Programm = 1 ;
      }
      else if (btData == "b" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 8 ;
      }
      else if (btData == "b" && external)  { // Switches to External Controller
        Programm = 8 ;
      }
      else if (btData == "c" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 2 ;
      }
      else if (btData == "c" && external)  { // Switches to External Controller
        Programm = 2 ;
      }
      else if (btData == "d" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 3 ;
      }
      else if (btData == "d" && external)  { // Switches to External Controller
        Programm = 3 ;
      }
      else if (btData == "e" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 4 ;
      }
      else if (btData == "e" && external)  { // Switches to External Controller
        Programm = 4 ;
      }
      else if (btData == "f" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 5 ;
      }
      else if (btData == "f" && external)  { // Switches to External Controller
        Programm = 5 ;
      }
      else if (btData == "g" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 6 ;
      }
      else if (btData == "g" && external)  { // Switches to External Controller
        Programm = 6 ;
      }
      else if (btData == "h" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 7 ;
      }
      else if (btData == "h" && external)  { // Switches to External Controller
        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)
  {
    external = true;
    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" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 1 ;
      }
      else if (btData == "a" && external)  { // Switches to External Controller
        Programm = 1 ;
      }
      else if (btData == "b" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 8 ;
      }
      else if (btData == "b" && external)  { // Switches to External Controller
        Programm = 8 ;
      }
      else if (btData == "c" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 2 ;
      }
      else if (btData == "c" && external)  { // Switches to External Controller
        Programm = 2 ;
      }
      else if (btData == "d" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 3 ;
      }
      else if (btData == "d" && external)  { // Switches to External Controller
        Programm = 3 ;
      }
      else if (btData == "e" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 4 ;
      }
      else if (btData == "e" && external)  { // Switches to External Controller
        Programm = 4 ;
      }
      else if (btData == "f" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 5 ;
      }
      else if (btData == "f" && external)  { // Switches to External Controller
        Programm = 5 ;
      }
      else if (btData == "g" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 6 ;
      }
      else if (btData == "g" && external)  { // Switches to External Controller
        Programm = 6 ;
      }
      else if (btData == "h" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 7 ;
      }
      else if (btData == "h" && external)  { // Switches to External Controller
        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)
  {
    external = true;
    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" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 1 ;
      }
      else if (btData == "a" && external)  { // Switches to External Controller
        Programm = 1 ;
      }
      else if (btData == "b" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 8 ;
      }
      else if (btData == "b" && external)  { // Switches to External Controller
        Programm = 8 ;
      }
      else if (btData == "c" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 2 ;
      }
      else if (btData == "c" && external)  { // Switches to External Controller
        Programm = 2 ;
      }
      else if (btData == "d" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 3 ;
      }
      else if (btData == "d" && external)  { // Switches to External Controller
        Programm = 3 ;
      }
      else if (btData == "e" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 4 ;
      }
      else if (btData == "e" && external)  { // Switches to External Controller
        Programm = 4 ;
      }
      else if (btData == "f" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 5 ;
      }
      else if (btData == "f" && external)  { // Switches to External Controller
        Programm = 5 ;
      }
      else if (btData == "g" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 6 ;
      }
      else if (btData == "g" && external)  { // Switches to External Controller
        Programm = 6 ;
      }
      else if (btData == "h" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 7 ;
      }
      else if (btData == "h" && external)  { // Switches to External Controller
        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)
  {
    external = true;
    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" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 1 ;
      }
      else if (btData == "a" && external)  { // Switches to External Controller
        Programm = 1 ;
      }
      else if (btData == "b" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 8 ;
      }
      else if (btData == "b" && external)  { // Switches to External Controller
        Programm = 8 ;
      }
      else if (btData == "c" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 2 ;
      }
      else if (btData == "c" && external)  { // Switches to External Controller
        Programm = 2 ;
      }
      else if (btData == "d" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 3 ;
      }
      else if (btData == "d" && external)  { // Switches to External Controller
        Programm = 3 ;
      }
      else if (btData == "e" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 4 ;
      }
      else if (btData == "e" && external)  { // Switches to External Controller
        Programm = 4 ;
      }
      else if (btData == "f" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 5 ;
      }
      else if (btData == "f" && external)  { // Switches to External Controller
        Programm = 5 ;
      }
      else if (btData == "g" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 6 ;
      }
      else if (btData == "g" && external)  { // Switches to External Controller
        Programm = 6 ;
      }
      else if (btData == "h" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 7 ;
      }
      else if (btData == "h" && external)  { // Switches to External Controller
        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)
  {
    external = true;
    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" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 1 ;
      }
      else if (btData == "a" && external)  { // Switches to External Controller
        Programm = 1 ;
      }
      else if (btData == "b" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 8 ;
      }
      else if (btData == "b" && external)  { // Switches to External Controller
        Programm = 8 ;
      }
      else if (btData == "c" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 2 ;
      }
      else if (btData == "c" && external)  { // Switches to External Controller
        Programm = 2 ;
      }
      else if (btData == "d" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 3 ;
      }
      else if (btData == "d" && external)  { // Switches to External Controller
        Programm = 3 ;
      }
      else if (btData == "e" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 4 ;
      }
      else if (btData == "e" && external)  { // Switches to External Controller
        Programm = 4 ;
      }
      else if (btData == "f" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 5 ;
      }
      else if (btData == "f" && external)  { // Switches to External Controller
        Programm = 5 ;
      }
      else if (btData == "g" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 6 ;
      }
      else if (btData == "g" && external)  { // Switches to External Controller
        Programm = 6 ;
      }
      else if (btData == "h" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 7 ;
      }
      else if (btData == "h" && external)  { // Switches to External Controller
        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)
  {
    external = true;
    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" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 1 ;
      }
      else if (btData == "a" && external)  { // Switches to External Controller
        Programm = 1 ;
      }
      else if (btData == "b" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 8 ;
      }
      else if (btData == "b" && external)  { // Switches to External Controller
        Programm = 8 ;
      }
      else if (btData == "c" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 2 ;
      }
      else if (btData == "c" && external)  { // Switches to External Controller
        Programm = 2 ;
      }
      else if (btData == "d" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 3 ;
      }
      else if (btData == "d" && external)  { // Switches to External Controller
        Programm = 3 ;
      }
      else if (btData == "e" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 4 ;
      }
      else if (btData == "e" && external)  { // Switches to External Controller
        Programm = 4 ;
      }
      else if (btData == "f" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 5 ;
      }
      else if (btData == "f" && external)  { // Switches to External Controller
        Programm = 5 ;
      }
      else if (btData == "g" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 6 ;
      }
      else if (btData == "g" && external)  { // Switches to External Controller
        Programm = 6 ;
      }
      else if (btData == "h" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 7 ;
      }
      else if (btData == "h" && external)  { // Switches to External Controller
        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)
  {
    external = true;
    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" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 1 ;
      }
      else if (btData == "a" && external)  { // Switches to External Controller
        Programm = 1 ;
      }
      else if (btData == "b" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 8 ;
      }
      else if (btData == "b" && external)  { // Switches to External Controller
        Programm = 8 ;
      }
      else if (btData == "c" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 2 ;
      }
      else if (btData == "c" && external)  { // Switches to External Controller
        Programm = 2 ;
      }
      else if (btData == "d" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 3 ;
      }
      else if (btData == "d" && external)  { // Switches to External Controller
        Programm = 3 ;
      }
      else if (btData == "e" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 4 ;
      }
      else if (btData == "e" && external)  { // Switches to External Controller
        Programm = 4 ;
      }
      else if (btData == "f" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 5 ;
      }
      else if (btData == "f" && external)  { // Switches to External Controller
        Programm = 5 ;
      }
      else if (btData == "g" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 6 ;
      }
      else if (btData == "g" && external)  { // Switches to External Controller
        Programm = 6 ;
      }
      else if (btData == "h" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 7 ;
      }
      else if (btData == "h" && external)  { // Switches to External Controller
        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)
  {
    external = false;
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);
    if (btSerial.available()) {
      btData = btSerial.readString();
      Serial.print(btData);
      if (btData == "a" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 1 ;
      }
      else if (btData == "a" && external)  { // Switches to External Controller
        Programm = 1 ;
      }
      else if (btData == "b" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 8 ;
      }
      else if (btData == "b" && external)  { // Switches to External Controller
        Programm = 8 ;
      }
      else if (btData == "c" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 2 ;
      }
      else if (btData == "c" && external)  { // Switches to External Controller
        Programm = 2 ;
      }
      else if (btData == "d" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 3 ;
      }
      else if (btData == "d" && external)  { // Switches to External Controller
        Programm = 3 ;
      }
      else if (btData == "e" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 4 ;
      }
      else if (btData == "e" && external)  { // Switches to External Controller
        Programm = 4 ;
      }
      else if (btData == "f" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 5 ;
      }
      else if (btData == "f" && external)  { // Switches to External Controller
        Programm = 5 ;
      }
      else if (btData == "g" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 6 ;
      }
      else if (btData == "g" && external)  { // Switches to External Controller
        Programm = 6 ;
      }
      else if (btData == "h" && !external) {
        digitalWrite(4, HIGH);
        digitalWrite(5, LOW);
        Programm = 7 ;
      }
      else if (btData == "h" && external)  { // Switches to External Controller
        Programm = 7 ;
      }
      else if  (btData == "i")  { // Switches to External Controller
        Programm = 9 ;
      }
    }
  }
  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;
}
 

Sephirot

Well-Known Member
2 Jun 2015
1,371
1,091
#26
Steh ich aufm Schlauch? Boolsch heißt doch wahrheitswert als wahr/falsch true/false.
Darum habe ich ja auch geschrieben Prinzipiell. Wofür steht den in der Digitaltechnik z.B bei Wahrheitstabellen true oder false? 1 und 0 natürlich. Innerhalb deiner IDE wird es zwar mit true und false gehandelt, aber letztendlich wird daraus in der Regel auch nur eine 1 oder 0.
 

ZeCjy

Honorable
7 Jan 2015
3,365
2,224
#27
Darum habe ich ja auch geschrieben Prinzipiell. Wofür steht den in der Digitaltechnik z.B bei Wahrheitstabellen true oder false? 1 und 0 natürlich. Innerhalb deiner IDE wird es zwar mit true und false gehandelt, aber letztendlich wird daraus in der Regel auch nur eine 1 oder 0.
Ja, kannst auch mit High/Low, -1 0 1 arbeiten etc. Aber beim Arduino kommt true/false (falls es auch anders geht weiß ich es nicht, kenne es aus der offiziellen Dokumentation so.