Hello all,
I am very new to arduino and coding in general. I am attempting to switch between animations on my neopixel strip when pressing different buttons in a bluetooth app. For example, when button ‘a’ is pressed I would like it to run a certain animation. Then when button ‘b’ is pressed I would like it to end the previous animation from button ‘a’ and begin a new animation when button ‘b’ is pressed. How can I go about accomplishing this task?
As of now I can get the first animation to run by pressing button ‘a’ but it does not break the loop and start a new loop when I press button ‘b’. Therefore, it just continuously runs the animation from button ‘a’.
Here is what I have for the code.
void setup(){
strip.begin();
strip.show();
Serial.begin(9600);
}
void loop(){
if(Serial.available()>0)
{
int data= Serial.read();
switch(data)
{
case’a’:STRIPON();break;
case’b’:STRIPOFF();break;
defult: break;
}
}
delay(50);
}
void STRIPON(){
int x=0;
while(x=0){
for (int i=0; i<=NUM_LEDS; i=i+2){
strip.setPixelColor(i, 25, 25, 25); // even pixels
strip.setPixelColor(i+1 , 0, 0, 25); // odd pixels
strip.show();
}
for (int i=0; i<= NUM_LEDS; i=i+2){
strip.setPixelColor(i, 0, 0, 0); // even pixels
strip.setPixelColor(i+1 , 0, 0, 0); // odd pixels
strip.show();
}
}
}
void STRIPOFF(){
for (int i=0; i<NUM_LEDS; i++){
strip.setPixelColor(i, 0, 0, 0);
strip.show();
}
}