LED Strip different modes (fade, single colors)

Hello!
I recently bought a RGB LED strip and wanted to programm my arduino to use my bluetoothmodule, which reads the input, so i can swith between the different modes.

If I activate the fade mode, my Arduino is stuck in a loop and i have to reset it :confused:
Maybe you can help me to fix my problem. i already tried many things but nothing worked.

int ledred=8;
int ledgreen=9;
int ledblue=10;
int tx=1;
int rx=0;
int inSerInt = 0;
int mode = 0;
int reset = 7;


void setup(){
  Serial.begin(9600);
  pinMode(ledred, OUTPUT);
  pinMode(ledgreen, OUTPUT);
  pinMode(ledblue, OUTPUT);
  pinMode(reset, OUTPUT);
  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);
  allpinslow();
  Serial.println("Eingabe bitte!");
}

void loop(){
    char inSerial[15];
    int i=0;
    int m=0;
    delay(500);                                         
    if (Serial.available() > 0) {             
       while (Serial.available() > 0) {
         inSerial[i]=Serial.read(); 
         i++;      
       }
       if(mode > 1)digitalWrite(reset, HIGH);
       inSerial[i]='\0';
      led(inSerial);
     }} 
     
void allpinslow()
{
digitalWrite(ledred, LOW);
digitalWrite(ledgreen, LOW);
digitalWrite(ledblue, LOW);
}     
  
void led(char inStr[]){   
  int i=0;
  int m=0;
  
  if(!strcmp(inStr,"red")){
mode++;    //Ledred ON
    allpinslow();
    digitalWrite(ledred, HIGH);
    Serial.println("Red ON");
    for(m=0;m<11;m++){
      inStr[m]=0;}
       i=0;}
       
  if(!strcmp(inStr,"green")){      //Ledgreen ON
  mode++;
    allpinslow();
    digitalWrite(ledgreen, HIGH);
    Serial.println("Green ON");
    for(m=0;m<11;m++){
      inStr[m]=0;}
       i=0;}
   
   if(!strcmp(inStr,"blue")){      //Ledblue ON
   mode++;
    allpinslow();
    digitalWrite(ledblue, HIGH);
    Serial.println("Blue ON");
    for(m=0;m<11;m++){
      inStr[m]=0;}
       i=0;}   

  if(!strcmp(inStr,"fade")){
    mode=1;
      allpinslow();
      Serial.println("Fade ON");
      int r, g, b;
      int FADESPEED;
      FADESPEED = 5;
      // fade from blue to violet
      if(mode == 1){
      for (r = 0; r < 256; r++) { 
        if(!strcmp(inStr,"fade")){
          analogWrite(ledred, r);
          delay(FADESPEED);
        }else{Serial.println(r);}
      } 
      // fade from violet to red
      for (b = 255; b > 0; b--) {
        if(!strcmp(inStr,"fade")){ 
          analogWrite(ledblue, b);
          delay(FADESPEED);
        }else{Serial.println(b);}
      } 
      // fade from red to yellow
      for (g = 0; g < 256; g++) {
        if(!strcmp(inStr,"fade")){ 
          analogWrite(ledgreen, g);
          delay(FADESPEED);
        }else{Serial.println(g);}
      } 
      // fade from yellow to green
      for (r = 255; r > 0; r--) {
        if(!strcmp(inStr,"fade")){  
          analogWrite(ledred, r);
          delay(FADESPEED);
        }else{Serial.println(r);}
      } 
      // fade from green to teal
      for (b = 0; b < 256; b++) {
        if(!strcmp(inStr,"fade")){  
          analogWrite(ledblue, b);
          delay(FADESPEED);
        }else{Serial.println(b);}
      } 
      // fade from teal to blue
      for (g = 255; g > 0; g--) {
        if(!strcmp(inStr,"fade")){  
          analogWrite(ledgreen, g);
          delay(FADESPEED);
        }else{Serial.println(g);}
      } 
    }}
        else{
    for(m=0;m<11;m++){
      inStr[m]=0;
    }
    i=0;
    
}
}

Thx :slight_smile:

I used a bit of coding from GreatScott and an other website for the fade because I didn’t want to write that much

Is it stuck forever or just until it has gone through that entire fade routine, which may take a while. The way the code is written, it will have to completely finish the entire routine through all the colors before it ever gets back out to check the serial line again.

Unirox:
I used a bit of coding from GreatScott and an other website for the fade because I didn't want to write that much

Then you're stuck with it working the way they want to. If you want it to work your way then you'll have to write code.

  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);

These pins belong to the Serial instance. Don’t f**k with them.

    for(m=0;m<11;m++){
      inStr[m]=0;}

You don’t understand the concept of “NULL-terminated array of chars”, do you? The NULL is a stop sign. How often do you see 11 stop signs at one corner, all facing the same way?

  if(!strcmp(inStr,"red")){

You don’t understand what strcmp() does, either, apparently.

      int FADESPEED;
      FADESPEED = 5;

Was it REALLY necessary to use two lines of code for this?

By convention, all capital letter names are reserved for constants. FASESPEED is not a constant.

    mode=1;
      if(mode == 1){

Is there ANY possible situation where the if statement will not evaluate to true? Is it necessary, given that the answer is no?