Controlling multiple RGB LEDs with on button

I have three RGB LEDs with a series of lighting effects for 11 buttons. (So when one button is pressed one effect will go off - the same effect on each RGB at the same time.)

I'm just wondering - how do I control this with a button through an if statement - this is the code I have currently and they all work find individually (I've only been able to test on one RGB so far - but will I have to create more pins - (4 pins for each 4 pin RGB so 16 pins) Also I keep getting the error 'setColor' was not declared in this scope for a few lines and I'm unsure why but otherwise the code seems fine..ish. (I've only shown two buttons to keep in word count)

int redPin = 9;
int greenPin = 10;
int bluePin = 11;
int orangePin = 1;
int purplePin = 2;
int yellowPin = 3;
int whitePin = 6;
int aquaPin = 7;
int tealPin = 8;

int btn1 = 4; // each different button
int btn2 = 5;
int btn3 = 6;
int btn4 = 7;
int btn5 = 8;
int btn6 = 9;
int btn7 = 10;
int btn8 = 11;
int btn9 = 12;
int btn10 = 13;
int btn11 = 14;

void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(orangePin, OUTPUT);
pinMode(purplePin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(whitePin, OUTPUT);
pinMode(aquaPin, OUTPUT);
pinMode(tealPin, OUTPUT);
}
void loop()
{

if (btn1, HIGH); //Africa
setColor(250, 0, 0); // red lowest brightness
delay(500);
setColor(255, 50, 0); // Orange
delay(500);
setColor(50, 0, 0); // red
delay(500);
setColor(140, 0, 0); // red
delay(500);
setColor(255, 0, 0); // red
delay(500);
setColor(140, 0, 0); // red
delay(500);
setColor(255, 255, 0); // yellow
delay(500);
//setColor(0, 255, 0); // green
// delay(1000);
//setColor(0, 0, 255); // blue
// delay(1000);
setColor(255, 255, 0); // yellow
delay(500);
//setColor(80, 0, 80); // purple
//delay(1000);
setColor(255, 50, 0); // Orange
delay(500);

if (btn2, HIGH); //Breeze
setColor(0, 0, 255); // red lowest brightness . (RED - BRIGHTNESS, GREEN, BLUE)
delay(1500);
setColor(0, 0, 150);
delay(1500);
setColor(0, 0, 255);
delay(1500);
//setColor(255, 50, 0); // Orange
//delay(500);
//setColor(50, 0, 0); // red
//delay(500);
//setColor(140, 0, 0); // red
//delay(500);
//setColor(255, 0, 0); // red
//delay(500);
//setColor(140, 0, 0); // red
//delay(500);
setColor(0, 5, 150); // yellow
delay(1500);
setColor(0, 0, 100); // green
delay(1500);
setColor(0, 0, 255); // blue
delay(1500);
setColor(80, 0, 80); // yellow
delay(1500);
//setColor(80, 0, 80); // purple
//delay(1000);
//setColor(255, 50, 0); // Orange
//delay(500);

}

void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);

}

Hi and welcome. Please have a look at How to use the forum and edit you post accordingly.

What I can see now:

  • If you have RGB leds, what is the aquaPin?

-Using blocking code (main culprit delay()) makes it hard to act on buttons.

  • If you have multiple almost the same items and you want to number them, let the compiler do the numbering and use arrays :slight_smile: Saves you a lot of work.

Hey thanks for your reply - I'm just going with colours because the LEDs accompany MP3 files on another set of code so the colours are just made up of ones that will show - they're not really significant haha and I used delays because some of the effects are lightening and need them to be slower than others and then dramatically increase speed

Yeah I'm not the best at arrays and I wasn't really sure how to use them I guess, my main worry right now is just getting a button to control 3 RGBs :stuck_out_tongue:

You fully missed the most important part of my post :wink:

septillion:
Please have a look at How to use the forum and edit you post accordingly.

And please don't post snippets :slight_smile: