Very new - would like to understand better RGB Leds

Hello,
I am new to programming in c and electronic. I have many 74hc595 and rgb 4 lead leds. I have been looking high and low for a basic example of controlling rgb leds.
I have found examples of running through an array, making leds flash but not controlling coloring.

I would like to start with one 74hc595 and a couple RGB led color control colors example.

I am a very visual person and need to see the wire layout and coding to control each led lead.

thanks, I am really grateful for the help.

I would like to start with one 74hc595 and a couple RGB led color control colors example.

If you are just starting out, just experiment with driving the RGB led from the Arduino directly( with series limiting resistors of course) then progress to the 595.

thanks,
I do understand that much. then I throw a 595 and a couple more RGB leds; I could not control the colors.

What I got out of this code: You set the pins to the color and pass into the function to generate the result. I know with the 595, I am dealing with arrays. I am banging my head over the control of each color.

help

/* 
 Adafruit Arduino - Lesson 3. RGB LED 
 */ 



 
int redPin = 3; 
int greenPin = 5; 
int bluePin = 6; 

void setup() 
{ 
  pinMode(redPin, OUTPUT); 
  pinMode(greenPin, OUTPUT); 
  pinMode(bluePin, OUTPUT); 
} 

void loop() 
{ 
  setColor(255, 0, 0);  // red 
  delay(2000); 
  setColor(0, 255, 0);  // green 
  delay(2000); 
  setColor(0, 0, 255);  // blue 
  delay(2000); 
  setColor(255, 255, 0);  // yellow 
  delay(2000);   
  setColor(0x4B, 0x0, 0x82); // indigo
  delay(200);   
  setColor(0x33, 0xCC, 0xFF); // 

  delay(200); 
  setColor(80, 0, 80);  // purple 
  delay(1000); 
  setColor(0, 255, 255);  // aqua 
  
  delay(500);
  
  setColor(0xFF, 0x0, 0x0); 
  delay(500); 
  setColor(0xFF, 0xFF, 0xFF); 
  delay(500); 
  setColor(0x00, 0x00, 0x99); 

} 



void setColor(int red, int green, int blue) 
{ 
  analogWrite(redPin, 255-red); 
  analogWrite(greenPin, 255-green); 
  analogWrite(bluePin, 255-blue); 
}

Think of an RGB LED as three separate LEDs. You can turn any of the pure colors on with a single LED. When you want more interesting colors, you need to blend the three colors together. The code example you are using is blending the colors together using PWM. Each LED is turned on and off rapidly so that the color you see is a blend.

The pins that are chosen in the example are important. They are capable of Pulse Width Modulation (PWM). If you don't understand PWM, look it up now.

When you add a component in between the Arduino and the RGB LED, you need to preserve the on/off cycling to keep the color. You have to continually write the shift register to turn the LEDs on and off in the right proportion to keep the color blend.

Consider the line
setColor(0x4B, 0x0, 0x82); // indigo
Red and Blue are blended together with a proportion of 0x4B to 0x82 with 255 being on all the time and 0 (like Green here) being off all the time.

There are specialty ICs for driving LEDs instead of a 595 depending on your configuration. Common anode or common cathode?

hello, said there are better ic for rgb led control? what do you recommend? Is the tcl5940nt a good one?

Hi, the easiest to use in my opinion is the ws2812b led. This has its own shift registers and pwm for colour mixing built in to the led itself. You can connect large numbers if these leds in a string to a single Arduino output. The leds are available in strips and on tiny individual pcbs. They are also known as "neopixels". There are a couple of libraries available to make them even easier to use.

Paul

Unfortunately the 74hc595 doesn't have hardware PWM-capabilities, making it harder to dim leds. Another disadvantage is that it can only handle 70mA, leaving only a few mA per led.

But... PWM using 595-chips can be done in software as well.

http://www.elcojacobs.com/shiftpwm/

Check out some of Kevin Darrah's video tutorials. They're long but very detailed and pretty easy to understand.

hello all,
I'm so new, I just learned that there is a difference between RGB leds - anode and cathode. I then learned that I have been using cathode with anode wire layout. I can not find any examples using cathode rgb leds with 7hc595 or the tlc5940nt I just received.

any help I am grateful.

HC595 can drive high outputs (marginally, 8-9mA) to turn on common cathode RGB LEDs - the cathode will connect to Gnd.

tlc5940 needs common anode LEDs, it can only sink current - the anode connects to +5. You will find most LED drivers are set up to sink current.