Go Down

Topic: RGB LEDs HELP!!!! (Read 1 time) previous topic - next topic

Shadown

hey guys,
I'm really new to the Arduino, so bear with me.
I've been (trying) to work with RGB LEDs. I have this big project/idea in my head, so i bought one RGB LED to see if this idea can be brought to life! So i have a 4 pin common anode LED. I've been experimenting with the LED library, using "void setValue(byte val)" to set each RGB color. It's working ok...but not really. Any help would be much appreciated!
I was also wondering how i would hook up 3 potentiometers, one to control the RED, one to control the GREEN, and one to control the BLUE. Thanks a ton!
":<> H@(Ke|) :"

AWOL

#1
Jun 30, 2009, 06:51 pm Last Edit: Jun 30, 2009, 06:59 pm by AWOL Reason: 1
Quote
working ok...but not really. Any help would be much appreciated!

So?
Where is it?

BTW there are plenty of threads with exactly this code in, on the forum.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

estranged

It would really help to see your sketch.

Shadown

I don't really have a code. I don't know what to do! I've tried doing something like this:

#include <LED.h>

LED led9 = LED(9);
LED led10 = LED(10);
LED led11 = LED(11);

void setup() {
}

void loop() {
led9.setValue(0);
led10.setValue(0);
led11.setValue(255);
}

But that's not really working. I figured that if i could get any color by setting the RGB colors to the byte value.

But my main problem is that when i try to connect a potentiometer, it grounds out and turns everything off! Any help with that!?!
Here's what i have:
Common Anode(+) to 5V
RED LED pin to 11
GREEN LED pin to 10
BLUE LED pin to 9
Potentiometer middle pin to Analog 2
Potentiometer Ground to GND
Potentiometer Power to 5V

Like i said. I would like to be able to control the RGB values with a Potentiometer. I only have one potentiometer at the time, so lets say that i would like to control the RED value and leave the the Green and Blue at high (or something like that). Thanks!  
":<> H@(Ke|) :"

AWOL

You MUST have current limiting resistors between your Arduino pins and the LEDs.

I'd break down the problem first.
Assuming you can get "Serial" to work, try reading values off your pots, and print them so that you can verify that the pot is working.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

EmilyJane

Quote
You [glow]MUST[/glow] have current limiting resistors between your Arduino pins and the LEDs.


Additionally, if your LED is truly common anode, you will have to invert the value you pass to setValue(), using something like

l
Code: [Select]
led9.setValue(intensity ^ 255);

Shadown

ahh. ok. I tested my potentiometer using the serial.println and it seemed to work fine. I will try the intensity thing and post back soon. Thanks for all the quick responses!
":<> H@(Ke|) :"

AWOL

You said when you connect the pot , it resets - what value pot have you got?

(well-spotted EJ, I just saw the LED-to-pin connection and knee-jerked.
I guess at low PWM ratios the LEDs and output pins would probably be OK without resistors, but as the ratio got higher, maybe the average current gets too great)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Shadown

#8
Jun 30, 2009, 07:30 pm Last Edit: Jun 30, 2009, 07:31 pm by Shadown Reason: 1
Hmm, i don't know. I just hooked up my Potentiometer and it worked fine. Didn't reset. Wierd. Anyway, i edited my code:  

led10.setValue(value ^ 255);

and that seemed to help a little. However when its all the way, one way...it'll get a deep red and as i start to turn it it gets whiter and whiter, then it goes back to red and does that about 4 times before the POT is all the way, the other way. Any suggestions?
":<> H@(Ke|) :"

EmilyJane

Let's see all the code.

AWOL

#10
Jun 30, 2009, 07:35 pm Last Edit: Jun 30, 2009, 07:38 pm by AWOL Reason: 1
"value = map (value, 0, 1023, 0, 255);"
before you call "setValue".
Or "value /= 4;"

analogRead goes 0...1023, analogWrite goes 0...255.

BTW red to "white"  sounds bad - better get those current limiters in soon, or it'll end in tears!
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


Shadown

YES! That worked! The map thingy! That's amazing! Thank you so much. So theoretically if i would get two more potentiometers and use the following code, i could get any color i want?

#include <LED.h>
int potPin1 = 1;
int potPin2 = 2;
int potPin3 = 3;
LED led9 = LED(9);
LED led10 = LED(10);
LED led11 = LED(11);

void setup() {
pinMode(potPin1, OUTPUT);
pinMode(potPin2, OUTPUT);
pinMode(potPin3, OUTPUT);
}

void loop() {
 int value1 = analogRead(potPin1);
 int val1 = map(value1, 0, 1023, 0,255);
 int value2 = analogRead(potPin2);
 int val2 = map(value2,0,1203,0,255);
 int value3 = analogRead(potPin3);
 int val3 = map(value3,0,1203,0,255);

 led9.setValue(val1 ^ 255);
 led10.setValue(val2 ^ 255);
 led11.setValue(val3 ^ 255);
}

That should do it shouldn't it?!?!?
Also, how many ohm resistor would i need? I have an 650mcd(green) 120mcd(blue) RGB LED with a FW current: 30mA(green/blue) 50mA (red)
":<> H@(Ke|) :"

EmilyJane

Yay!

50 ohm resistors will work for all three. It calculates more like 60 for the red but 50 should be close enough.

Shadown

:D Thanks guys! You guys are great! I don't mean to keep bothering you, but do any of you know anything about processing? I was thinking of a way to control the RGB values using processing instead of Potentiometers (or maybe use both!) I can't seem to find any good tutorials on Processing and the Arduino, so i was wondering if any of you knew?! Thanks again!  ;)
":<> H@(Ke|) :"

Go Up