Have a problem to quit a loop

Hello Community,

I have a problem with my code, I wrote a code for a NeoPixel Led Ring.

I wrote some modes like farbcircle or rainbow there are working but, my problem is I cant quit the mode if i want. I tried a break in a loop but nothing work. I hope someone can help me.

#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 6
#define NUMPIXELS 8
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

SoftwareSerial BTSerial(2, 3); //RX | Tx

char data;
int helligkeit=255;

void setup() {
  Serial.begin(9600);
  Serial.println("Start communication");
  BTSerial.begin(38400);

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  strip.setBrightness(255);

}

void loop() {
  if(BTSerial.available()>0)  {
    data = BTSerial.read();
    BTSerial.println(data);
  }
    
    switch(data) {
      case '0': //aus
          colorWipe(strip.Color(0, 0, 0),0);
      break;  

      case '1': //Stark
            helligkeit = min( 255, helligkeit + 25);
            Serial.println(helligkeit);
            strip.setBrightness(helligkeit);
            strip.show();
            data = ' ';
      break; 

      case '2': //Schwach
            helligkeit = max( 30, helligkeit - 25);
            Serial.println(helligkeit);
            strip.setBrightness(helligkeit);
            strip.show();
            data = ' ';
      break; 
      
      case 'a': //rot
          colorWipe(strip.Color(255, 0, 0),50);
      break;

      case 'b': //dunkel orange
          colorWipe(strip.Color(255, 25, 0),50);
      break;

      case 'c': //orange
          colorWipe(strip.Color(255, 50, 0),50);
      break;
      
      case 'd': //hellorange
          colorWipe(strip.Color(255, 75, 0),50);
      break;

      case 'e': //Gelb
          colorWipe(strip.Color(255, 155, 0),50);
      break;
      
      case 'f': //Grün
          colorWipe(strip.Color(0, 255, 0),50);
      break;
     
      case 'g'://Hellgrün
          colorWipe(strip.Color(50, 255, 50),50);
      break;  
      
      case 'h'://Hellblau_1
          colorWipe(strip.Color(75, 255, 255),50);
      break;  

      case 'i'://Hellblau_2
          colorWipe(strip.Color(0, 200, 255),50);
      break;  

      case 'j'://Hellblau_3
          colorWipe(strip.Color(0, 60, 255),50);
      break;  

      case 'k'://Blau
          colorWipe(strip.Color(0, 0, 255),50);
      break; 

      case 'l'://Dunkelblau
          colorWipe(strip.Color(75, 0, 255),50);
      break;    
      
      case 'm'://Lila
          colorWipe(strip.Color(150, 0, 255),50);
      break;
      
      case 'n'://Hell_lila
          colorWipe(strip.Color(200, 25, 255),50);
      break;

      case 'o'://Pink
          colorWipe(strip.Color(255, 0, 255),50);
      break;

      case 'p'://Weiss
          colorWipe(strip.Color(255, 255, 255),50);
      break;  

      case 'q': // Farb wechsel
          colorchange(100);  //speed von farbwechsel   
      break;

      case 'r': //Blink
        colorWipe(strip.Color(255, 0, 0), 50);  // Red
        colorWipe(strip.Color(0, 255, 0), 50);  // Green
        colorWipe(strip.Color(0, 0, 255), 50);  // Blue
        theaterChase(strip.Color(  0,   0, 127), 50); // Blue
        theaterChase(strip.Color(127,   0,   0), 50); // Red
        theaterChase(strip.Color(0,   127,   0), 50); // Green
      break;  

      case 's': //Regenbogen
        rainbowCycle(25);     
      break;  

      case 't': //Zufall
            long randNumber = random(16);
              if(randNumber==0)
                data='a';
              if(randNumber==1)
                data='b';
              if(randNumber==2)
                data='c';
              if(randNumber==3)
                data='d';
              if(randNumber==4)
                data='e';
              if(randNumber==5)
                data='f';
              if(randNumber==6)
                data='g';
              if(randNumber==7)
                data='h';
              if(randNumber==8)
                data='i';
              if(randNumber==9)
                data='j';
              if(randNumber==10)
                data='k';
              if(randNumber==11)
                data='l';
              if(randNumber==12)
                data='m';
              if(randNumber==13)
                data='n';
              if(randNumber==14)
                data='o';
              if(randNumber==15)
                data='p';         
         break;      
        
    }  
  
  delay(10);    

} 

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.setBrightness(helligkeit);
        strip.show();
        data = ' ';
    delay(wait);
  }
}
//Wichtig für den Regenbogen
void colorchange(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i*1+j) & 255));
    }
        strip.show();
        data = ' ';
    delay(wait);
  }
}

void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*10; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));     
    }
        strip.show();
        data = ' ';
    delay(wait);
  }
}

void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
        strip.show();
        data = ' ';

      delay(wait);

      for (int i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } 
  else if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } 
  else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

The rainbows and sparkles are good for showing off the capabilities of the neopixels. Unfortunately they are not useful when you need to do other things, like checking for new inputs.

You need to treat each special effect as an animation that proceeds forwards on a specific time schedule. Then you can write your main loop() to look at all the inputs, make decisions and look at its watch to decide if it is time to move the animation forwards one step.

For further reading, try Planning and implementing an Arduino Program and BlinkWithoutDelay

That is a poor solution. Every different animation function must know how to check all the inputs. If there are many inputs, such as limit switches for a motor you're driving then that will get very complex.

If the Bluetooth input is not one you are looking (maybe it is a newline or space character) then you have just lost your place in the animation. Even if the main loop() knows to go back to the rainbow, it must start again.

And still the sketch can do nothing else. It can't control another group of Christmas lights or an LCD screen or anything.

Also: fix your quote tags.