I need help with this rgb light code

Hey guys! I'm a new Arduino user and for a project in my computer science class, we have to take one of the openings projects (that Arduino provides - SIK circuits) and further develop them. I decided to do circuit #3- RGB LED. I intended to further the code by adding two more led lights and coding them all to do different color at a time. To do this, I thought it was as simple as just adding 3 more lights and copy and pasting certain codes for 2 more RGB lights, well that didn't work. :astonished: So i have attached a picture of my Arduino and the code below and hopefully you guys can help me out to see where I went wrong. Thanks so much that would be so helpful.

my code:

//light 1
const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;

const int DISPLAY_TIME = 1000; // used in mainColors() to determine the
// length of time each color is displayed.

//light 2
const int RED_PIN2 = 8;
const int GREEN_PIN2 = 6;
const int BLUE_PIN2 = 7;

const int DISPLAY_TIME2 = 1000; // used in mainColors() to determine the
// length of time each color is displayed.

//light 3
const int RED_PIN3 = 1;
const int GREEN_PIN3 = 2;
const int BLUE_PIN3 = 3;

const int DISPLAY_TIME3 = 1000; // used in mainColors() to determine the
// length of time each color is displayed.

void setup() //Configure the Arduino pins to be outputs to drive the LEDs
{

pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);

pinMode(RED_PIN2, OUTPUT);
pinMode(GREEN_PIN2, OUTPUT);
pinMode(BLUE_PIN2, OUTPUT);

pinMode(RED_PIN3, OUTPUT);
pinMode(GREEN_PIN3, OUTPUT);
pinMode(BLUE_PIN3, OUTPUT);
}

void loop()

{
mainColors(); // Red, Green, Blue, Yellow, Cyan, Purple, White
//showSpectrum(); // Gradual fade from Red to Green to Blue to Red
}

void mainColors()
{
// all LEDs off
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);
delay(DISPLAY_TIME);

digitalWrite(RED_PIN2, LOW);
digitalWrite(GREEN_PIN2, LOW);
digitalWrite(BLUE_PIN2, LOW);
delay(DISPLAY_TIME2);

digitalWrite(RED_PIN3, LOW);
digitalWrite(GREEN_PIN3, LOW);
digitalWrite(BLUE_PIN3, LOW);
delay(DISPLAY_TIME3);

// Red
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);
delay(DISPLAY_TIME);

digitalWrite(RED_PIN2, HIGH);
digitalWrite(GREEN_PIN2, LOW);
digitalWrite(BLUE_PIN2, LOW);
delay(DISPLAY_TIME2);

digitalWrite(RED_PIN3, HIGH);
digitalWrite(GREEN_PIN3, LOW);
digitalWrite(BLUE_PIN3, LOW);
delay(DISPLAY_TIME3);

// Green
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, LOW);
delay(DISPLAY_TIME);

digitalWrite(RED_PIN2, LOW);
digitalWrite(GREEN_PIN2, HIGH);
digitalWrite(BLUE_PIN2, LOW);
delay(DISPLAY_TIME2);

digitalWrite(RED_PIN3, LOW);
digitalWrite(GREEN_PIN3, HIGH);
digitalWrite(BLUE_PIN3, LOW);
delay(DISPLAY_TIME3);

// Blue
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
delay(DISPLAY_TIME);

digitalWrite(RED_PIN2, LOW);
digitalWrite(GREEN_PIN2, LOW);
digitalWrite(BLUE_PIN2, HIGH);
delay(DISPLAY_TIME2);

digitalWrite(RED_PIN3, LOW);
digitalWrite(GREEN_PIN3, LOW);
digitalWrite(BLUE_PIN3, HIGH);
delay(DISPLAY_TIME3);

// Yellow (Red and Green)
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, LOW);
delay(DISPLAY_TIME);

digitalWrite(RED_PIN2, HIGH);
digitalWrite(GREEN_PIN2, HIGH);
digitalWrite(BLUE_PIN2, LOW);
delay(DISPLAY_TIME2);

digitalWrite(RED_PIN3, HIGH);
digitalWrite(GREEN_PIN3, HIGH);
digitalWrite(BLUE_PIN3, LOW);
delay(DISPLAY_TIME3);

// Cyan (Green and Blue)
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);
delay(DISPLAY_TIME);

digitalWrite(RED_PIN2, LOW);
digitalWrite(GREEN_PIN2, HIGH);
digitalWrite(BLUE_PIN2, HIGH);
delay(DISPLAY_TIME2);

digitalWrite(RED_PIN3, LOW);
digitalWrite(GREEN_PIN3, HIGH);
digitalWrite(BLUE_PIN3, HIGH);
delay(DISPLAY_TIME3);

// Purple (Red and Blue)
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);
delay(DISPLAY_TIME);

digitalWrite(RED_PIN2, HIGH);
digitalWrite(GREEN_PIN2, LOW);
digitalWrite(BLUE_PIN2, HIGH);
delay(DISPLAY_TIME2);

digitalWrite(RED_PIN3, HIGH);
digitalWrite(GREEN_PIN3, LOW);
digitalWrite(BLUE_PIN3, HIGH);
delay(DISPLAY_TIME3);

// White (turn all the LEDs on)
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);
delay(DISPLAY_TIME);

digitalWrite(RED_PIN2, HIGH);
digitalWrite(GREEN_PIN2, HIGH);
digitalWrite(BLUE_PIN2, HIGH);
delay(DISPLAY_TIME2);

digitalWrite(RED_PIN3, HIGH);
digitalWrite(GREEN_PIN3, HIGH);
digitalWrite(BLUE_PIN3, HIGH);
delay(DISPLAY_TIME3);
}

void showSpectrum()
{
for (int x = 0; x <= 767; x++)
{
RGB(x); // Increment x and call RGB() to progress through colors.
delay(10); // Delay for 10 ms (1/100th of a second) - to help the "smoothing"
}

void RGB(int color)
{
int redIntensity;
int greenIntensity;
int blueIntensity;

color = constrain(color, 0, 767); // constrain the input value to a range of values from 0 to 767

// if statement breaks down the "color" into three ranges:
if (color <= 255) // RANGE 1 (0 - 255) - red to green
{
redIntensity = 255 - color; // red goes from on to off
greenIntensity = color; // green goes from off to on
blueIntensity = 0; // blue is always off
}
else if (color <= 511) // RANGE 2 (256 - 511) - green to blue
{
redIntensity = 0; // red is always off
greenIntensity = 511 - color; // green on to off
blueIntensity = color - 256; // blue off to on
}
else // RANGE 3 ( >= 512)- blue to red
{
redIntensity = color - 512; // red off to on
greenIntensity = 0; // green is always off
blueIntensity = 767 - color; // blue on to off
}

// "send" intensity values to the Red, Green, Blue Pins using analogWrite()
analogWrite(RED_PIN, redIntensity);
analogWrite(GREEN_PIN, greenIntensity);
analogWrite(BLUE_PIN, blueIntensity);
}

Oh dear... ah well, the code of the gradient depends on using pwmPins, 9 10 & 11 are there are 3 more on an Uno 3,5 & 6. the mainColor() functions is well, not so pretty... strangely enough what you might get away with doing for visual effect is connect 3 strips (you could actually go upto 6) and just alter the way you connect the colors, say on strip1 9,10 & 11 = RG & B, on strip2 it is GB & R etc.. i don't know what your grade would be (maybe if you put all 6 combinations it would be ok..), but it would actually sort of be what you wanted to achieve, though not in the way you planned to do it. If on the other hand you have access to WS2812 LED strip the sky would be the limit !

Check your braces {} (try CTL - T). One of your functions is never completed so that code doesn't even compile. In my experience code that won't compile never does work.

Also read "How to use this forum - please read" and follow the instructions when posting code.

Steve

slipstick:
Check your braces {} (try CTL - T). One of your functions is never completed so that code doesn't even compile.

You know that is the worst bug you can get, you miss a brace somewhere and the compiler claims that none of your functions have previously been declared, but it does not seem to be able to point you to the function lacking a brace. With a program this size i think i'd find it, but it happens to me in bigger programs. Does anyone know where to post for IDE improvements ?

If your code is properly indented those errors are incredibly easy to spot. And the IDE already has a very useful Auto Format command.

Steve