Using a 2-color LED
#1
Posted 06 May 2011 - 09:39 PM
I just recently got (back) into electronics. I managed to put out my first Netduino project, that simulates a traffic light (yay ).
While buying LEDs at my local Fry's, I accidentally picked up a 2-color LED. It says that a different color will be shown if polarity is reversed. I used my multimeter in diode-test mode, and sure enough, I got a green color when I switched the probes.
Now the question is, how to do this programmatically. Suppose I have one of the LED legs connected to D13 and the other to GND.
I can easily light the LED by using an OutputPort, but how can I reverse it's polarity? All I can write to the port is 'true or 'false'.
Do I need another electric component to reverse the polarity, or is it possible to achieve with code only?
Do I use an analog pin? What am I missing?
Thanks for your time.
Guy
#2
Posted 06 May 2011 - 10:13 PM
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#3
Posted 06 May 2011 - 10:22 PM
I can easily light the LED by using an OutputPort, but how can I reverse it's polarity? All I can write to the port is 'true or 'false'.
Do I need another electric component to reverse the polarity, or is it possible to achieve with code only?
Easy :-) You use two ports, one wired to each leg. Write true to pin and false to pin 2 to get green, and reverse it for red. Make sure you use a current limiting resistor on one of the legs.
#4
Posted 06 May 2011 - 11:58 PM
#5
Posted 07 May 2011 - 03:50 AM
#6
Posted 07 May 2011 - 02:52 PM
Hi Guy, unfortunately you cannot use the tristate port to drive a bi-color led.
The simplest way is as Dan explained.
Two ports are the very minimum, because you need three states: green, red and off.
You MAY use a tristate port, but only adding some hardware.
Polarity apart, I suggest always to add a simple transistor to increase the led current. Even the MCU is robust enough, I'd prefer to stress it as few as possible.
Cheers
I believe he can actually. If he sets one port to input and the other to true, the lights will be off (both). Tristate ports have the ability of a output and input port. You can set a tristate port to true, false, or input. I don't have any of those LEDs so i can't test it per se, but I've done pretty much the same thing in my Charlieplexing post. You are correct, 2 ports is the minimum.
Here you can find a tutorial on the TristatePort class, http://forums.netdui...tateport-class/
#7
Posted 07 May 2011 - 03:19 PM
That was exactly my ideaI believe he can actually. If he sets one port to input and the other to true, the lights will be off (both). Tristate ports have the ability of a output and input port. You can set a tristate port to true, false, or input. I don't have any of those LEDs so i can't test it per se, but I've done pretty much the same thing in my Charlieplexing post. You are correct, 2 ports is the minimum.
Haven't got the mats to test it right now since I'm at a weekend trip with my family, but in theory thas was what I was thinking of.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#8
Posted 07 May 2011 - 03:35 PM
Attached Files
#9
Posted 07 May 2011 - 03:57 PM
ah gotchaOmar, I meant only *one* (tristate) port is not enough. It has exactly three states, but its driver cannot used to drive a led in the desired manner.
Of course a tristate can be used as a normal push-pull port, but he needs at least two pins.
However, I attached a schematic about the simplest way to drive a bi-color led using just one 3-state port.
If the port is a PWM also, it is possible to create several shades only adjusting the duty-cycle.
Fault: there is no a decent current driver such a transitor, so that the current will be very small.
Cheers
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users