Pages: [1]   Go Down
Author Topic: [RESOLVED] led RGB strange colors  (Read 608 times)
0 Members and 1 Guest are viewing this topic.
Ticino (Switzerland)
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I'm trying to use my common anode rgb led but i don't understand how the mixing colors work.
RGB led: R = 1.9V , G = 3.0V , B = 3.0V; 20mA.
I calculated the resistor (5V - 1.9V) / 20mA = 150 ohm for Red
                                 (5V - 3.0V) / 20mA = 100 ohm for Green and Blue.

I tried many colors but the don't seems right:
(i tried with Blue)

analogWrite(red, 0);
analogWrite(green, 0);
analogWrite(blue, 255);

But the color was yellow. Is it right? For me is really strange smiley
I also tried to work with a RGB color picker online:
i tried a pink rgb color (235, 47, 166) but the result was a blue-green color.

Please help! smiley Thank you!



« Last Edit: January 19, 2013, 10:40:08 am by NicolaBu » Logged

Ticino (Switzerland)
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I resolved my problem! I don't know why but my values were inverted (0 was 255), so i mapped my color variables.
Thanks anyway smiley-wink
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4089
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

With a common-anode LED, pulling a pin low will illuminate it. Pulling red and green low together will give yellow. For blue, try:

Code:
analogWrite(red, 255);
analogWrite(green, 255);
analogWrite(blue, 0);

This is why programmers are crazy, it comes from having to think backwards sometimes smiley-grin
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Create yourself a function that does the inverting for you, and then you don't have to worry about it afterwards.

I.e

Void setRGB(int redBrightbess, int greenBeightness, int blueBrightness)

Within your function take each value and invert the brightness before do an analogWrite, such as analogWrite(redPin, 255 - redBrightness)

Set the relevant LED pin assignments elsewhere.

Call your function like setRGB(255,0,0) to turn the red lED on.

If you want to do it for more than one RGB LED then you could pass the pin numbers for each one to the function or even do in a number of other ways.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 633
Posts: 34514
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Create yourself a function that does the inverting for you
Or even simpler just subtract the value you want to set from 255 like this:-
Code:
analogWrite(red, 255-redVal);
analogWrite(green, 255-greenVal);
analogWrite(blue, 255-blueVal);
Logged

Pages: [1]   Go Up
Jump to: