Two arduino rgb leds

HI,
I'm currently working on a school project which requires me to seperately conrol two different rgb leds on the same board. The problem i'm currently running into is coding it to have different colours at the same time and change it in the same timing. Does anyone have any examples or simple solutions any help is greatly appericiated.

Welcome to the forum

Where are you stuck ?

What type of LEDs are you using ?
Are they normal, dumb RGB LEDs or addressable LEDs ?

Can you make one light up ?
Can you make two light up ?

well i've been using the rgb leds from the arduino uno basic starter kit currently i've only been able to make one rgb light up even if i've connected the GNDs together. I can have two ight up by connecting the gnd and wires together but cannot individually control them.

Connect the GNDs of both LEFDs to GND on the Arduino. Connect the R, G and B pins of one LED to 3 separate pins. Connect the R, G and B pins of the second LED to 3 other pins. By controlling the state of the 6 pins you can get any colour combination you like on either LED. The colour on the 2 LED's can be the same or different. You decide

Hey,
So I've got the 2nd rbg to start working but i'm having trouble controlling the 2nd rbg light
I'm using the led code from the kit with a few changes


#define B 3  //value of 1st led
#define G 5
#define R 6
#define I 13 //values of 2nd led
#define O 12
#define P 11
void setup()
{
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
pinMode(I, OUTPUT);
pinMode(O, OUTPUT);
pinMode(P, OUTPUT);
digitalWrite(R, HIGH);
digitalWrite(G, LOW);
digitalWrite(B, LOW);
digitalWrite(I, LOW);
digitalWrite(O,LOW);
digitalWrite(P,LOW);
}

// define variables
int RValue;
int GValue;
int BValue;
int IValue;
int OValue;
int PValue;
// main loop
void loop()
{
#define delayTime 10 // fading time between colors

RValue = 255; // choose a value between 1 and 255 to change the color.
GValue = 0;
BValue = 0;
IValue = 255;
OValue =0;
PValue =0;
for(int i = 0; i < 255; i += 1) // fades out red bring green full when i=255
{
analogWrite(R, RValue);
analogWrite(G, GValue);
analogWrite(I, IValue);
analogWrite(O, OValue);
delay(delayTime);
}

RValue = 128;
GValue = 128;
BValue = 0;
IValue = 0;
OValue =255;
PValue =0;

for(int i = 0; i < 255; i += 1) // fades out green bring blue full when i=255
{
analogWrite(G, GValue);
analogWrite(B, BValue);
analogWrite(O, OValue);
analogWrite(P, PValue);
delay(delayTime);
}

RValue = 0;
GValue = 255;
BValue = 0;
IValue = 255;
OValue =255;
PValue =255;

for(int i = 0; i < 255; i += 1) // fades out blue bring red full when i=255
{
analogWrite(B, BValue);
analogWrite(R, RValue);
analogWrite(P, PValue);
analogWrite(I, IValue);
delay(delayTime);
}
}

But i'm not sure why the colour is not changing the way i want

What happens when you run the sketch and what do you want to happen instead ?

Hey
so right now i can control them individually but the problem i'm running into is adjusting the colour of the second Led my 1st led goes from red yellow green
and my 2nd rgb led is supposed to go from green yellow red
but then 2nd rgb led seems to stay green all the time
if i run the 2nd rgb led as red yellow green it works fine

To make things easier to see what is going on the first thing that I would do is to give all of the pin names and variables sensible names that associate R, G and B pins and values with the appropriate LED

This will not fix the problem, but a pin name of O, for instance, means nothing when reading the code but a name such as G_pin_2 would make it recognisable as the green pin on LED 2 as opposed to G_pin_1 (the green pin on LED 1)

Hey
Thanks you've been amazing hope to see you in the forum again!!!

Is the sketch working as you want now ?

If so, then please post it here in a new reply, explain what you changed and mark the topic as solved

If not, then post your latest version

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.