Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Using a 2-color LED


  • Please log in to reply
8 replies to this topic

#1 Traveling Tech Guy

Traveling Tech Guy

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 06 May 2011 - 09:39 PM

Sorry if this comes across as a newbie question.
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 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 06 May 2011 - 10:13 PM

you could use the built-in tristateport class on two pins. it can be set off, input and output.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 Dan Morphis

Dan Morphis

    Advanced Member

  • Members
  • PipPipPip
  • 188 posts

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 Traveling Tech Guy

Traveling Tech Guy

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts

Posted 06 May 2011 - 11:58 PM

Thanks Dan! It is easy (took 3 minutes to write code and verify) :) Stefan, where can i learn about that tristateport class? Sounds like a better way to use this LED in the future than what I'm doing right now. Thank you both. I love easy answers :)

#5 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 May 2011 - 03:50 AM

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
Biggest fault of Netduino? It runs by electricity.

#6 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

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 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 07 May 2011 - 03:19 PM

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.

That was exactly my idea :D
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.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#8 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 May 2011 - 03:35 PM

Omar, 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

Attached Files


Biggest fault of Netduino? It runs by electricity.

#9 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 07 May 2011 - 03:57 PM

Omar, 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

ah gotcha




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.