RGB Strip Effects Switching (Like a Christmas Tree)

Hello,
I’m still reasonably new to Arduino and am stuck and can’t find the right information I need on Google.

Here’s my problem – I have lots of fade, random effects etc. for my RGB strip what all work fine individually. This next bit is what I’m stuck on - what I now want to do is find a option to put all these into one file and control them from say eight push buttons connected to my Arduino Mega, one button for each set of RGB effects and a extra button to stop the RGB effect instantly. What I also need the eight buttons to do is stop the current RGB effect running and start the new one as some of the RGB effects are very long. (five minutes)

I’ve been banging my head on this, if anyone even knows how to stop the current running programme at a button press that would be a great help, I’ve included a RGB effect example so you know what effects I mean.

#define REDPIN 10
#define GREENPIN 11
#define BLUEPIN 12
#define FADESPEED 25     // make this higher to slow down
void setup() {
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
}
void loop() {
int r, g, b;
 
// fade from blue to violet
for (r = 0; r < 256; r++) { 
analogWrite(REDPIN, r);
delay(FADESPEED);
} 
// fade from violet to red
for (b = 255; b > 0; b--) { 
analogWrite(BLUEPIN, b);
delay(FADESPEED);
} 
// fade from red to yellow
for (g = 0; g < 256; g++) { 
analogWrite(GREENPIN, g);
delay(FADESPEED);
} 
// fade from yellow to green
for (r = 255; r > 0; r--) { 
analogWrite(REDPIN, r);
delay(FADESPEED);
} 
// fade from green to teal
for (b = 0; b < 256; b++) { 
analogWrite(BLUEPIN, b);
delay(FADESPEED);
} 
// fade from teal to blue
for (g = 255; g > 0; g--) { 
analogWrite(GREENPIN, g);
delay(FADESPEED);
} 
}

This question can't be answered in an easy "here's the code" way, but the first step is to get rid of the delay statements.

Google blink without delay to get started.

Also, I wanted to do the same exact thing as you when I first started, so going through the topics I've created might help you.

I never thought about using the Arduinos onboard timer, I'll have a look at that this afternoon at work.

But basically you have a onboard timer running constantly in milliseconds ( millis() ) and you just keep resetting your variables ( previousMillis in the example ) to the timer.

Just need to integrate this into my effects, my first thought is I can get rid of the for statement and use a red = red +1 every time the millis reaches the interval.

Thanks for that its a great starting point.

Yes, the reason for getting rid of the delays is that you want to detect a button push. Delay halts the mcu, so if you press a button while the mcu is in the delay function, the mcu won't see the button push.... And since the delay takes a lot more time than the other instructions, you'd be lucky to capture half the button presses