Became Hot Network Question
2 Fixed syntax highlighting.
source | link

I'm sending data to Arduino through the mobile app.So So far, all the code has been running consistently. 

#include <SoftwareSerial.h>
#define FASTLED_INTERNAL
#include <FastLED.h>
#define NUM_LEDS_PER_STRIP 48
SoftwareSerial bluetooth(53,52);    // TX,RX                               
int bar_analog=0;                                    
int head_analog=0;
int bar_anim=0;
int anim=0;
int motor_speed=1;
int direct=0;
int level=0;
CRGB strip1[NUM_LEDS_PER_STRIP];
CRGB strip2[NUM_LEDS_PER_STRIP];
CRGB strip3[NUM_LEDS_PER_STRIP];
CRGB strip4[NUM_LEDS_PER_STRIP];
boolean debug = true;
int IN1a=49;
int IN2a=48;
int PWM1=3;
int IN1b=22;
int IN2b=23;
int PWM2=4;
int hiz=100;
int PWM_kare=2;
int INA_kare = 51;  
int INB_kare = 50; //LED '+'sı OUTPUT B'de olduğu için INB'yi  HIGH yapıyoruz.
void m1_cw() {
digitalWrite(IN1a,HIGH);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,hiz);
}
void m1_ccw() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,HIGH);
analogWrite(PWM1,hiz);
}
void m2_cw() {
digitalWrite(IN1b,HIGH);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,hiz);
}
void m2_ccw() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,HIGH);
analogWrite(PWM2,hiz);
}
void m1_stop() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,0);
}
void m2_stop() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,0);
}
void mast_up() {
digitalWrite(24,HIGH);
digitalWrite(25,LOW);
}
void mast_down() {
digitalWrite(24,LOW);
digitalWrite(25,HIGH);
}
void mast_stop() {
digitalWrite(24,LOW);
digitalWrite(25,LOW);
}
void kare() {
analogWrite(PWM_kare,head_analog);
digitalWrite(INB_kare, HIGH);
digitalWrite(INA_kare, LOW);
}
void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}
}
void setup() {
  Serial.begin(9600);                              
  bluetooth.begin(9600);                           
  Serial.println("Program is starting...");              
  Serial.println("by Berke Ogulcan Parlak"); 
pinMode(IN1a,OUTPUT);
pinMode(IN2a,OUTPUT);
pinMode(IN1b,OUTPUT);
pinMode(IN2b,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(PWM2,OUTPUT);
pinMode(24,OUTPUT);
pinMode(25,OUTPUT);
pinMode(INA_kare, OUTPUT);
pinMode(INB_kare, OUTPUT);
pinMode(PWM_kare, OUTPUT);
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
digitalWrite(PWM1,LOW);
digitalWrite(PWM2,LOW);  
digitalWrite(24,LOW);
digitalWrite(25,LOW);
digitalWrite(INA_kare, LOW);
digitalWrite(INB_kare, LOW);
digitalWrite(PWM_kare, LOW); 
FastLED.addLeds<NEOPIXEL, 26>(strip1, NUM_LEDS_PER_STRIP); 
FastLED.addLeds<NEOPIXEL, 28>(strip2, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 30>(strip3, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 32>(strip4, NUM_LEDS_PER_STRIP);
FastLED.setBrightness(0); 
}

void loop() {
  while (bluetooth.available())                    
    {                                                
      bar_analog = bluetooth.parseInt();              
      head_analog = bluetooth.parseInt();
      bar_anim = bluetooth.parseInt();
      anim = bluetooth.parseInt();
      motor_speed = bluetooth.parseInt();
      direct = bluetooth.parseInt();
      level = bluetooth.parseInt();
      if (debug) {                                  
        Serial.print("Bar Brightness: ");                        
        Serial.println(bar_analog);
        Serial.print("Bar Animation Type: ");
        Serial.println(bar_anim);
        Serial.print("Headlight Brightness: ");
        Serial.println(head_analog);
        Serial.print("Strip Animation Type: ");
        Serial.println(anim);
        Serial.print("Motor Speed Level: ");
        Serial.println(motor_speed);
        Serial.print("Direction: ");
        Serial.println(direct);
        Serial.print("Mast Goes: ");
        Serial.println(level);
        Serial.println("--------------------------------");
      }
      if (bluetooth.read() == '\n') {               

  }} 
        kare();            
       if(direct==1) { //ileri
  m1_ccw();
  m2_ccw(); 
  }
else if(direct==2) { //geri
  m1_cw();
  m2_cw(); 
  }
else if(direct==3) { //sol
  m1_ccw();
  m2_cw(); 
  }
else if(direct==4) { //sağ
  m1_cw();
  m2_ccw(); 
  }
else if(direct==0) { //durur
  m1_stop();
  m2_stop(); 
  }
if(level==1) { //mast yukarı
  mast_up(); 
  }
else if(level==2) { //mast aşağı
  mast_down(); 
  }
else if(level==0) { //mast durur
  mast_stop(); 
  }
if(anim==2) {
  strip_dim();
  }
else if(anim==0) {
  strip_stop();
  }
  }
#include <SoftwareSerial.h>
#define FASTLED_INTERNAL
#include <FastLED.h>
#define NUM_LEDS_PER_STRIP 48
SoftwareSerial bluetooth(53,52);    // TX,RX                               
int bar_analog=0;                                    
int head_analog=0;
int bar_anim=0;
int anim=0;
int motor_speed=1;
int direct=0;
int level=0;
CRGB strip1[NUM_LEDS_PER_STRIP];
CRGB strip2[NUM_LEDS_PER_STRIP];
CRGB strip3[NUM_LEDS_PER_STRIP];
CRGB strip4[NUM_LEDS_PER_STRIP];
boolean debug = true;
int IN1a=49;
int IN2a=48;
int PWM1=3;
int IN1b=22;
int IN2b=23;
int PWM2=4;
int hiz=100;
int PWM_kare=2;
int INA_kare = 51;  
int INB_kare = 50; //LED '+'sı OUTPUT B'de olduğu için INB'yi  HIGH yapıyoruz.
void m1_cw() {
digitalWrite(IN1a,HIGH);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,hiz);
}
void m1_ccw() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,HIGH);
analogWrite(PWM1,hiz);
}
void m2_cw() {
digitalWrite(IN1b,HIGH);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,hiz);
}
void m2_ccw() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,HIGH);
analogWrite(PWM2,hiz);
}
void m1_stop() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,0);
}
void m2_stop() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,0);
}
void mast_up() {
digitalWrite(24,HIGH);
digitalWrite(25,LOW);
}
void mast_down() {
digitalWrite(24,LOW);
digitalWrite(25,HIGH);
}
void mast_stop() {
digitalWrite(24,LOW);
digitalWrite(25,LOW);
}
void kare() {
analogWrite(PWM_kare,head_analog);
digitalWrite(INB_kare, HIGH);
digitalWrite(INA_kare, LOW);
}
void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}
}
void setup() {
  Serial.begin(9600);                              
  bluetooth.begin(9600);                           
  Serial.println("Program is starting...");              
  Serial.println("by Berke Ogulcan Parlak"); 
pinMode(IN1a,OUTPUT);
pinMode(IN2a,OUTPUT);
pinMode(IN1b,OUTPUT);
pinMode(IN2b,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(PWM2,OUTPUT);
pinMode(24,OUTPUT);
pinMode(25,OUTPUT);
pinMode(INA_kare, OUTPUT);
pinMode(INB_kare, OUTPUT);
pinMode(PWM_kare, OUTPUT);
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
digitalWrite(PWM1,LOW);
digitalWrite(PWM2,LOW);  
digitalWrite(24,LOW);
digitalWrite(25,LOW);
digitalWrite(INA_kare, LOW);
digitalWrite(INB_kare, LOW);
digitalWrite(PWM_kare, LOW); 
FastLED.addLeds<NEOPIXEL, 26>(strip1, NUM_LEDS_PER_STRIP); 
FastLED.addLeds<NEOPIXEL, 28>(strip2, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 30>(strip3, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 32>(strip4, NUM_LEDS_PER_STRIP);
FastLED.setBrightness(0); 
}

void loop() {
  while (bluetooth.available())                    
    {                                                
      bar_analog = bluetooth.parseInt();              
      head_analog = bluetooth.parseInt();
      bar_anim = bluetooth.parseInt();
      anim = bluetooth.parseInt();
      motor_speed = bluetooth.parseInt();
      direct = bluetooth.parseInt();
      level = bluetooth.parseInt();
      if (debug) {                                  
        Serial.print("Bar Brightness: ");                        
        Serial.println(bar_analog);
        Serial.print("Bar Animation Type: ");
        Serial.println(bar_anim);
        Serial.print("Headlight Brightness: ");
        Serial.println(head_analog);
        Serial.print("Strip Animation Type: ");
        Serial.println(anim);
        Serial.print("Motor Speed Level: ");
        Serial.println(motor_speed);
        Serial.print("Direction: ");
        Serial.println(direct);
        Serial.print("Mast Goes: ");
        Serial.println(level);
        Serial.println("--------------------------------");
      }
      if (bluetooth.read() == '\n') {               

  }} 
        kare();            
       if(direct==1) { //ileri
  m1_ccw();
  m2_ccw(); 
  }
else if(direct==2) { //geri
  m1_cw();
  m2_cw(); 
  }
else if(direct==3) { //sol
  m1_ccw();
  m2_cw(); 
  }
else if(direct==4) { //sağ
  m1_cw();
  m2_ccw(); 
  }
else if(direct==0) { //durur
  m1_stop();
  m2_stop(); 
  }
if(level==1) { //mast yukarı
  mast_up(); 
  }
else if(level==2) { //mast aşağı
  mast_down(); 
  }
else if(level==0) { //mast durur
  mast_stop(); 
  }
if(anim==2) {
  strip_dim();
  }
else if(anim==0) {
  strip_stop();
  }
  }
void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}
}
void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}
}

I'm sending data to Arduino through the mobile app.So far, all the code has been running consistently.

#include <SoftwareSerial.h>
#define FASTLED_INTERNAL
#include <FastLED.h>
#define NUM_LEDS_PER_STRIP 48
SoftwareSerial bluetooth(53,52);    // TX,RX                               
int bar_analog=0;                                    
int head_analog=0;
int bar_anim=0;
int anim=0;
int motor_speed=1;
int direct=0;
int level=0;
CRGB strip1[NUM_LEDS_PER_STRIP];
CRGB strip2[NUM_LEDS_PER_STRIP];
CRGB strip3[NUM_LEDS_PER_STRIP];
CRGB strip4[NUM_LEDS_PER_STRIP];
boolean debug = true;
int IN1a=49;
int IN2a=48;
int PWM1=3;
int IN1b=22;
int IN2b=23;
int PWM2=4;
int hiz=100;
int PWM_kare=2;
int INA_kare = 51;  
int INB_kare = 50; //LED '+'sı OUTPUT B'de olduğu için INB'yi  HIGH yapıyoruz.
void m1_cw() {
digitalWrite(IN1a,HIGH);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,hiz);
}
void m1_ccw() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,HIGH);
analogWrite(PWM1,hiz);
}
void m2_cw() {
digitalWrite(IN1b,HIGH);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,hiz);
}
void m2_ccw() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,HIGH);
analogWrite(PWM2,hiz);
}
void m1_stop() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,0);
}
void m2_stop() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,0);
}
void mast_up() {
digitalWrite(24,HIGH);
digitalWrite(25,LOW);
}
void mast_down() {
digitalWrite(24,LOW);
digitalWrite(25,HIGH);
}
void mast_stop() {
digitalWrite(24,LOW);
digitalWrite(25,LOW);
}
void kare() {
analogWrite(PWM_kare,head_analog);
digitalWrite(INB_kare, HIGH);
digitalWrite(INA_kare, LOW);
}
void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}
}
void setup() {
  Serial.begin(9600);                              
  bluetooth.begin(9600);                           
  Serial.println("Program is starting...");              
  Serial.println("by Berke Ogulcan Parlak"); 
pinMode(IN1a,OUTPUT);
pinMode(IN2a,OUTPUT);
pinMode(IN1b,OUTPUT);
pinMode(IN2b,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(PWM2,OUTPUT);
pinMode(24,OUTPUT);
pinMode(25,OUTPUT);
pinMode(INA_kare, OUTPUT);
pinMode(INB_kare, OUTPUT);
pinMode(PWM_kare, OUTPUT);
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
digitalWrite(PWM1,LOW);
digitalWrite(PWM2,LOW);  
digitalWrite(24,LOW);
digitalWrite(25,LOW);
digitalWrite(INA_kare, LOW);
digitalWrite(INB_kare, LOW);
digitalWrite(PWM_kare, LOW); 
FastLED.addLeds<NEOPIXEL, 26>(strip1, NUM_LEDS_PER_STRIP); 
FastLED.addLeds<NEOPIXEL, 28>(strip2, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 30>(strip3, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 32>(strip4, NUM_LEDS_PER_STRIP);
FastLED.setBrightness(0); 
}

void loop() {
  while (bluetooth.available())                    
    {                                                
      bar_analog = bluetooth.parseInt();              
      head_analog = bluetooth.parseInt();
      bar_anim = bluetooth.parseInt();
      anim = bluetooth.parseInt();
      motor_speed = bluetooth.parseInt();
      direct = bluetooth.parseInt();
      level = bluetooth.parseInt();
      if (debug) {                                  
        Serial.print("Bar Brightness: ");                        
        Serial.println(bar_analog);
        Serial.print("Bar Animation Type: ");
        Serial.println(bar_anim);
        Serial.print("Headlight Brightness: ");
        Serial.println(head_analog);
        Serial.print("Strip Animation Type: ");
        Serial.println(anim);
        Serial.print("Motor Speed Level: ");
        Serial.println(motor_speed);
        Serial.print("Direction: ");
        Serial.println(direct);
        Serial.print("Mast Goes: ");
        Serial.println(level);
        Serial.println("--------------------------------");
      }
      if (bluetooth.read() == '\n') {               

  }} 
        kare();            
       if(direct==1) { //ileri
  m1_ccw();
  m2_ccw(); 
  }
else if(direct==2) { //geri
  m1_cw();
  m2_cw(); 
  }
else if(direct==3) { //sol
  m1_ccw();
  m2_cw(); 
  }
else if(direct==4) { //sağ
  m1_cw();
  m2_ccw(); 
  }
else if(direct==0) { //durur
  m1_stop();
  m2_stop(); 
  }
if(level==1) { //mast yukarı
  mast_up(); 
  }
else if(level==2) { //mast aşağı
  mast_down(); 
  }
else if(level==0) { //mast durur
  mast_stop(); 
  }
if(anim==2) {
  strip_dim();
  }
else if(anim==0) {
  strip_stop();
  }
  }
void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}
}

I'm sending data to Arduino through the mobile app. So far, all the code has been running consistently. 

#include <SoftwareSerial.h>
#define FASTLED_INTERNAL
#include <FastLED.h>
#define NUM_LEDS_PER_STRIP 48
SoftwareSerial bluetooth(53,52);    // TX,RX                               
int bar_analog=0;                                    
int head_analog=0;
int bar_anim=0;
int anim=0;
int motor_speed=1;
int direct=0;
int level=0;
CRGB strip1[NUM_LEDS_PER_STRIP];
CRGB strip2[NUM_LEDS_PER_STRIP];
CRGB strip3[NUM_LEDS_PER_STRIP];
CRGB strip4[NUM_LEDS_PER_STRIP];
boolean debug = true;
int IN1a=49;
int IN2a=48;
int PWM1=3;
int IN1b=22;
int IN2b=23;
int PWM2=4;
int hiz=100;
int PWM_kare=2;
int INA_kare = 51;  
int INB_kare = 50; //LED '+'sı OUTPUT B'de olduğu için INB'yi  HIGH yapıyoruz.
void m1_cw() {
digitalWrite(IN1a,HIGH);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,hiz);
}
void m1_ccw() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,HIGH);
analogWrite(PWM1,hiz);
}
void m2_cw() {
digitalWrite(IN1b,HIGH);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,hiz);
}
void m2_ccw() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,HIGH);
analogWrite(PWM2,hiz);
}
void m1_stop() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,0);
}
void m2_stop() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,0);
}
void mast_up() {
digitalWrite(24,HIGH);
digitalWrite(25,LOW);
}
void mast_down() {
digitalWrite(24,LOW);
digitalWrite(25,HIGH);
}
void mast_stop() {
digitalWrite(24,LOW);
digitalWrite(25,LOW);
}
void kare() {
analogWrite(PWM_kare,head_analog);
digitalWrite(INB_kare, HIGH);
digitalWrite(INA_kare, LOW);
}
void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}
}
void setup() {
  Serial.begin(9600);                              
  bluetooth.begin(9600);                           
  Serial.println("Program is starting...");              
  Serial.println("by Berke Ogulcan Parlak"); 
pinMode(IN1a,OUTPUT);
pinMode(IN2a,OUTPUT);
pinMode(IN1b,OUTPUT);
pinMode(IN2b,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(PWM2,OUTPUT);
pinMode(24,OUTPUT);
pinMode(25,OUTPUT);
pinMode(INA_kare, OUTPUT);
pinMode(INB_kare, OUTPUT);
pinMode(PWM_kare, OUTPUT);
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
digitalWrite(PWM1,LOW);
digitalWrite(PWM2,LOW);  
digitalWrite(24,LOW);
digitalWrite(25,LOW);
digitalWrite(INA_kare, LOW);
digitalWrite(INB_kare, LOW);
digitalWrite(PWM_kare, LOW); 
FastLED.addLeds<NEOPIXEL, 26>(strip1, NUM_LEDS_PER_STRIP); 
FastLED.addLeds<NEOPIXEL, 28>(strip2, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 30>(strip3, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 32>(strip4, NUM_LEDS_PER_STRIP);
FastLED.setBrightness(0); 
}

void loop() {
  while (bluetooth.available())                    
    {                                                
      bar_analog = bluetooth.parseInt();              
      head_analog = bluetooth.parseInt();
      bar_anim = bluetooth.parseInt();
      anim = bluetooth.parseInt();
      motor_speed = bluetooth.parseInt();
      direct = bluetooth.parseInt();
      level = bluetooth.parseInt();
      if (debug) {                                  
        Serial.print("Bar Brightness: ");                        
        Serial.println(bar_analog);
        Serial.print("Bar Animation Type: ");
        Serial.println(bar_anim);
        Serial.print("Headlight Brightness: ");
        Serial.println(head_analog);
        Serial.print("Strip Animation Type: ");
        Serial.println(anim);
        Serial.print("Motor Speed Level: ");
        Serial.println(motor_speed);
        Serial.print("Direction: ");
        Serial.println(direct);
        Serial.print("Mast Goes: ");
        Serial.println(level);
        Serial.println("--------------------------------");
      }
      if (bluetooth.read() == '\n') {               

  }} 
        kare();            
       if(direct==1) { //ileri
  m1_ccw();
  m2_ccw(); 
  }
else if(direct==2) { //geri
  m1_cw();
  m2_cw(); 
  }
else if(direct==3) { //sol
  m1_ccw();
  m2_cw(); 
  }
else if(direct==4) { //sağ
  m1_cw();
  m2_ccw(); 
  }
else if(direct==0) { //durur
  m1_stop();
  m2_stop(); 
  }
if(level==1) { //mast yukarı
  mast_up(); 
  }
else if(level==2) { //mast aşağı
  mast_down(); 
  }
else if(level==0) { //mast durur
  mast_stop(); 
  }
if(anim==2) {
  strip_dim();
  }
else if(anim==0) {
  strip_stop();
  }
  }
void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}
}
1
source | link

Arduino Bluetooth communication is slowing down because of the 'for' loop!

I'm sending data to Arduino through the mobile app.So far, all the code has been running consistently.

#include <SoftwareSerial.h>
#define FASTLED_INTERNAL
#include <FastLED.h>
#define NUM_LEDS_PER_STRIP 48
SoftwareSerial bluetooth(53,52);    // TX,RX                               
int bar_analog=0;                                    
int head_analog=0;
int bar_anim=0;
int anim=0;
int motor_speed=1;
int direct=0;
int level=0;
CRGB strip1[NUM_LEDS_PER_STRIP];
CRGB strip2[NUM_LEDS_PER_STRIP];
CRGB strip3[NUM_LEDS_PER_STRIP];
CRGB strip4[NUM_LEDS_PER_STRIP];
boolean debug = true;
int IN1a=49;
int IN2a=48;
int PWM1=3;
int IN1b=22;
int IN2b=23;
int PWM2=4;
int hiz=100;
int PWM_kare=2;
int INA_kare = 51;  
int INB_kare = 50; //LED '+'sı OUTPUT B'de olduğu için INB'yi  HIGH yapıyoruz.
void m1_cw() {
digitalWrite(IN1a,HIGH);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,hiz);
}
void m1_ccw() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,HIGH);
analogWrite(PWM1,hiz);
}
void m2_cw() {
digitalWrite(IN1b,HIGH);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,hiz);
}
void m2_ccw() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,HIGH);
analogWrite(PWM2,hiz);
}
void m1_stop() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,0);
}
void m2_stop() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,0);
}
void mast_up() {
digitalWrite(24,HIGH);
digitalWrite(25,LOW);
}
void mast_down() {
digitalWrite(24,LOW);
digitalWrite(25,HIGH);
}
void mast_stop() {
digitalWrite(24,LOW);
digitalWrite(25,LOW);
}
void kare() {
analogWrite(PWM_kare,head_analog);
digitalWrite(INB_kare, HIGH);
digitalWrite(INA_kare, LOW);
}
void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}
}
void setup() {
  Serial.begin(9600);                              
  bluetooth.begin(9600);                           
  Serial.println("Program is starting...");              
  Serial.println("by Berke Ogulcan Parlak"); 
pinMode(IN1a,OUTPUT);
pinMode(IN2a,OUTPUT);
pinMode(IN1b,OUTPUT);
pinMode(IN2b,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(PWM2,OUTPUT);
pinMode(24,OUTPUT);
pinMode(25,OUTPUT);
pinMode(INA_kare, OUTPUT);
pinMode(INB_kare, OUTPUT);
pinMode(PWM_kare, OUTPUT);
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
digitalWrite(PWM1,LOW);
digitalWrite(PWM2,LOW);  
digitalWrite(24,LOW);
digitalWrite(25,LOW);
digitalWrite(INA_kare, LOW);
digitalWrite(INB_kare, LOW);
digitalWrite(PWM_kare, LOW); 
FastLED.addLeds<NEOPIXEL, 26>(strip1, NUM_LEDS_PER_STRIP); 
FastLED.addLeds<NEOPIXEL, 28>(strip2, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 30>(strip3, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 32>(strip4, NUM_LEDS_PER_STRIP);
FastLED.setBrightness(0); 
}

void loop() {
  while (bluetooth.available())                    
    {                                                
      bar_analog = bluetooth.parseInt();              
      head_analog = bluetooth.parseInt();
      bar_anim = bluetooth.parseInt();
      anim = bluetooth.parseInt();
      motor_speed = bluetooth.parseInt();
      direct = bluetooth.parseInt();
      level = bluetooth.parseInt();
      if (debug) {                                  
        Serial.print("Bar Brightness: ");                        
        Serial.println(bar_analog);
        Serial.print("Bar Animation Type: ");
        Serial.println(bar_anim);
        Serial.print("Headlight Brightness: ");
        Serial.println(head_analog);
        Serial.print("Strip Animation Type: ");
        Serial.println(anim);
        Serial.print("Motor Speed Level: ");
        Serial.println(motor_speed);
        Serial.print("Direction: ");
        Serial.println(direct);
        Serial.print("Mast Goes: ");
        Serial.println(level);
        Serial.println("--------------------------------");
      }
      if (bluetooth.read() == '\n') {               

  }} 
        kare();            
       if(direct==1) { //ileri
  m1_ccw();
  m2_ccw(); 
  }
else if(direct==2) { //geri
  m1_cw();
  m2_cw(); 
  }
else if(direct==3) { //sol
  m1_ccw();
  m2_cw(); 
  }
else if(direct==4) { //sağ
  m1_cw();
  m2_ccw(); 
  }
else if(direct==0) { //durur
  m1_stop();
  m2_stop(); 
  }
if(level==1) { //mast yukarı
  mast_up(); 
  }
else if(level==2) { //mast aşağı
  mast_down(); 
  }
else if(level==0) { //mast durur
  mast_stop(); 
  }
if(anim==2) {
  strip_dim();
  }
else if(anim==0) {
  strip_stop();
  }
  }

But when I added the for loop to the code, all the data started to shift.(When I press the button from the application 'lag' occurs and the data is mixed.)I mentioned that part of the code below.Why does the data shift?

void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık 
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show(); 
}
}