Hi,
First off, thank you for taking the time to offer your advice and helping me out.
I am totally new to Arduino and am loving learning how to do things. I have read through a few basic examples such as 'blink' and one on RGB LED.
While I can successfully control / program one RGB led with colours, fades delays etc I now would like to move to controlling two RGB leds so each is independent of each other.
Using the basic programming for one RGB led and also some coding from the 'several things at once' example I have compiled the code below.
This has been successful in getting BOTH leds to cycle through the colours using the six pwm pins, goal one achieved ... go me!
Here is the code I am using to achieve this so far:
const int red_A_Pin = 3; // the pin numbers for the 1st LED
const int green_A_Pin = 5;
const int blue_A_Pin = 6;
const int red_B_Pin = 11; // the pin numbers for the 2nd LED
const int green_B_Pin = 10;
const int blue_B_Pin = 9;
//uncomment this line if using a Common Anode LED
#define COMMON_ANODE
void setup()
{
pinMode(red_A_Pin, OUTPUT);
pinMode(green_A_Pin, OUTPUT);
pinMode(blue_A_Pin, OUTPUT);
pinMode(red_B_Pin, OUTPUT);
pinMode(green_B_Pin, OUTPUT);
pinMode(blue_B_Pin, OUTPUT);
}
void loop()
{
setColor(255, 0, 0); // red
delay(1000);
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(0, 255, 255); // aqua
delay(1000);
}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(red_A_Pin, red);
analogWrite(green_A_Pin, green);
analogWrite(blue_A_Pin, blue);
analogWrite(red_B_Pin, red);
analogWrite(green_B_Pin, green);
analogWrite(blue_B_Pin, blue);
}
Goal Two:
What I would like to do now is to separate the two RGB leds so they both do something different. At present they are both running the same cycle of colours albeit not in sync but that is irrelevant.
What I would like to achieve is RGB_A to be BLUE while RGB_B would be RED.
I think the part of the coding I need to change is this part:
void loop()
{
setColor(255, 0, 0); // red
delay(1000);
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(0, 255, 255); // aqua
delay(1000);
}
But I do not know what I need to be using. I'm guessing it will be something which defines A and B leds somehow. I have tried adding A and B like this: setColor_A or setColor_B bu I get error messages
Could someone point me in the right direction please
I am using an Arduino Uno, resistors and LED - RGB clear common anode
Thank you for your time and any help / advice you are willing to give.
Note to mods - I'm fairly confident I have the right section of the forum, if not please feel free to move my post. But do let me know where it's moved too