Go Down

Topic: [Solved]Incorrect colours from RGB LED (Read 821 times) previous topic - next topic

stonez56

Sep 21, 2014, 01:33 pm Last Edit: Sep 21, 2014, 03:55 pm by stonez56 Reason: 1
Need help to get correct colours from RGB common anode LEDs.
It's weird that the red colour code is 255,0,0 but I need to pass 255,255,0 to my Arduino mini pro to get red colour.
Also, 0.255.255 to get green and 255,0,255 to get blue. Most samples I found only the web, they only need single 255 to get R,G,B colours correctly.

Please help!

I have verified all the pins and they should be all correct.
RGB LED pins are connected to Arduino mini pro:
R=pin 6
Comm andode =pin VCC
G=pin 5
B=pin 3


I need the code below to get me red colour:
Code: [Select]

 analogWrite(PIN_RED,  255);
 analogWrite(PIN_GREEN,  255);
 analogWrite(PIN_BLUE,  0);


Mac OS 10.9.4
Arduino mini pro 16Mzh

Stonez56

spycatcher2k

Where is your common connected? Is it a common Anode(+ve) or common Cathode(-ve) RGB LED, If its in GND at the moment,, change it to +5v and vice versa
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

stonez56


Quote

Where is your common connected? Is it a common Anode(+ve) or common Cathode(-ve) RGB LED, If its in GND at the moment,, change it to +5v and vice versa

Thanks for the quick reply!

LED Common is now connected to VCC. I tried to connect the common to GND, then it won't work at all.


elac

Using common anode LED, 255 is off and 0 is full on.
If pins are connected correctly:
Code: [Select]
  analogWrite(PIN_RED,  0);
  analogWrite(PIN_GREEN,  255);
  analogWrite(PIN_BLUE,  255);

Will turn red fully on.
It's all about the skills

bobcousins


I have verified all the pins and they should be all correct.
RGB LED pins are connected to Arduino mini pro:
R=pin 6
Comm andode =pin VCC
G=pin 5
B=pin 3


I need the code below to get me red colour:
Code: [Select]

 analogWrite(PIN_RED,  255);
 analogWrite(PIN_GREEN,  255);
 analogWrite(PIN_BLUE,  0);



That means you have your led connections reversed! It's happened before. :)

You've got PIN_GREEN connected to Anode and PIN_BLUE connected to red cathode, which is why that particular code lights up the red led.
Please ask questions in the forum so everyone can benefit. PM me for paid work.

stonez56

Quote

Using common anode LED, 255 is off and 0 is full on.
If pins are connected correctly:
Code: [Select]

  analogWrite(PIN_RED,  0);
  analogWrite(PIN_GREEN,  255);
  analogWrite(PIN_BLUE,  255);

Will turn red fully on.

Hi elac,
Thank you so much! This is exactly what happen to my RGB LED!
I tested and it worked! 

However, the colour code input might have R 86, G 201, B 100. How should I handle this conversion?
Do you have a sample I can take a look? Thanks!

Stonez56

elac

Subtract the values from 255 and use the difference.
Example: R=86: 255-86=169,  G=201: 255-201=54, B=100: 255-100=155
 
Code: [Select]
analogWrite(PIN_RED, 169);
analogWrite(PIN_GREEN, 54);
analogWrite(PIN_BLUE, 155);


It's all about the skills

stonez56

Hi elac,
Quote

Subtract the values from 255 and use the difference.
Example: R=86: 255-86=169,  G=201: 255-201=54, B=100: 255-100=155

It worked! I take 255 to minus the original R,G,B code and the colour showing correctly now.
Thanks!!

elac

It's all about the skills

Go Up