Acidmods
Acid Mods Community Area
=> Discussion Boards => Spam & Chat => Topic started by: PspKicks316 on November 29, 2009, 08:42:15 AM
-
At the moment I only have common cathode RGB leds...but I need to drive the colors separately with PWM.
I've got the + wired to the PWM source and the color - wired to GND.
Obviously, using just this I can't control each of them separately.
How would I do this, then? ><
-
It sounds like you might have common anode LEDs (common + lead, separate - leads). The configuration depends on what you are driving the LEDs with, one way is to have the common anode of the three LEDs connected directly to the + power supply, and the switching transistors and current limiting resistors for each separate color can be placed between the cathode leads and ground.
-
Oh right. I'm always getting cathode and anode mixed up.
And, would you be able to be a little more descriptive? I don't think I get what you mean, haha.
-
How many LEDs are you trying to drive, and what are you driving them with?
-
An Arduino to drive them, and I'm only driving 1 RGB led at the moment (testing stuff out).
I'm using PWM to fade each color separately...or trying to.
I'm familiar with PWM on the Arduino and know what I'm doing, so that's not a problem.
-
Ok, that helps. If you are just testing stuff out then you can :
- connect the common anode pin of the RGB LED to your +5v supply
- connect appropriately valued current limiting resistors in series between the cathode leads for each individual color and the PWM pins on your arduino
Since microcontrollers aren't intended for driving high current loads directly, it is a better idea to use external transistors for switching, but you can get away with it in cases like this providing you keep the current low enough.
Note that if your code is set up for common cathode LEDs this will invert the PWM effect since they will now illuminate when the pin is low instead of high. You can adjust for this by inverting the variables that are sent to your PWM generation routine.
-
Invert....like as in negative values?
I think I'm missing something here. PWM can be used on the negative lead...? I thought PWM was positive. PWM goes from 0-255 on this..
EDIT: WOAH I GOT IT. Awesome. Thank you so much Blizzrad!
-
By invert I mean using the bitwise compliment (~) of the variable, so ~255 = 0, and ~0 = 255.
When set as outputs, the I/O pins on a microcontroller can source or sink current depending on the potential of what is connected to them. The PWM is switching your arduino pin continually between 0v and 5v, so if an LED with 5v on its anode has its cathode lead connected to the PWM pin, current will flow into the pin when it is at 0v, and no current will flow when it is at 5v since the potential is equal.
edit: Just saw your edit, glad to see you got it working.
-
That is so awesome. That really helped a lot. Thanks!