2 LEDs and one pin left


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 54
  1. #1
    Join Date
    Mar 2006
    Location
    China
    Posts
    266

    Default 2 LEDs and one pin left

    Hi All,

    I have one red LED and one GREEN led and a few resistors and only ONE pin left on my MCU. It would be nice if there is a way to turn on green or red or have them both off.

    Since the pin has 3 states it might be possible but today my brain just can't see how. Current goes in .. one LED is on... Current goes out.. the other one is on. But it is possible to have them both turned off without haveing any leaking current when the pin is in tri-state?

    I never plan to have them on at the same time... just both off or one or the other on.

    thanks!

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Output HIGH
    Output LOW
    Input

    Maybe
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default doh

    and what makes the current not flow thru any of them when the pin is in INPUT?

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    From a data sheet.
    Setting a
    TRISA bit (= 1) will make the corresponding PORTA pin
    an input (i.e., put the corresponding output driver in a
    Hi-Impedance mode)
    http://en.wikipedia.org/wiki/High_impedance
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    1,0
    0,1
    0,0

    LEDs on these states won't be possible by one pin.
    Instead, use 4017 with one pin.

    I have an example here:
    http://www.picbasic.co.uk/forum/showthread.php?t=6548&
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Can't you?
    Name:  dual-led.png
Views: 2240
Size:  9.4 KB

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    My turn to say DOH!!!

    No matter how you connect two LEDs without extra hardware there will be feed back between the two.

    A couple transistors or sayzer's solution are in order for this one.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    How many DOHs are allowed in one day???

    DUH code
    Code:
    BLINK:  
         HIGH PORTG.4 
         PAUSE 250 
         LOW PORTG.4  
         PAUSE 250   
         TRISG.4 = 1 
         PAUSE 2000    
         GOTO BLINK
    And
    Name:  LEDs.jpg
Views: 2198
Size:  15.4 KB
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Mar 2006
    Location
    China
    Posts
    266


    Did you find this post helpful? Yes | No

    Default well

    Then we have the problem with the idle current.... 2 resistors in serie between Vdd and Vss is going to drain the battery. I like the idea! but the idle current will be almost half of what the LED uses when it is turned on (sssuming 5V Vdd and 2V voltagedrop over the led)

    I dont have my lab stuff here.. does anyone think the idle current might be lower in the circuit i have attached.. or will smoke come out :-)

    Sure there are many ways to solve the problem by adding more things but I am still hoping this will work...

    or it will be DOOH and an other design.

    Thank you!
    Attached Images Attached Images  

  10. #10
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Jumper,

    You can use "one LED" only like the one in the link below. This is pretty much two LEDs put together. It is a red-green 3mm LED.

    http://futurlec.com/LED/LED3RG.shtml

    Quote Originally Posted by sayzer View Post
    1,0
    0,1
    0,0

    LEDs on these states won't be possible by one pin.
    Instead, use 4017 with one pin.

    I have an example here:
    http://www.picbasic.co.uk/forum/showthread.php?t=6548&
    However, the bad news is that Sayzer is right. You can't get three states "0,0", "0,1", and "1,0" with only one MCU pin.

    Robert

  11. #11
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rsocor01 View Post

    However, the bad news is that Sayzer is right. You can't get three states "0,0", "0,1", and "1,0" with only one MCU pin.
    Really? Because I am using Dave's code on a 18F26J50 (3.3 volt) with no resistors, and it works like a charm. Red, Blue, off
    Name:  dual-led3-3.PNG
Views: 2328
Size:  13.9 KB
    Code:
    BLINK:  
         HIGH PORTA.0 
         PAUSE 250 
         LOW PORTA.0  
         PAUSE 250   
         TRISA.0 = 1 
         PAUSE 2000    
         GOTO BLINK
    Last edited by ScaleRobotics; - 13th July 2010 at 22:48.

  12. #12
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scalerobotics View Post
    Really? Because I am using Dave's code on a 18F26J50 (3.3 volt) with no resistors, and it works like a charm. Red, Blue, off

    Code:
    BLINK:  
         HIGH PORTA.0 
         PAUSE 2500 
         LOW PORTA.0  
         PAUSE 2500   
         TRISA.0 = 1 
         PAUSE 20000    
         GOTO BLINK
    DOH,

    The trick is in the TRISA.0 = 1 to get both off (the 0,0 state). Nice!

    Robert

  13. #13
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I think this page explains what Walter is doing pretty well ...
    http://www.batsocks.co.uk/readme/p_tut_led16.htm
    DT

  14. #14


    Did you find this post helpful? Yes | No

    Default

    Simplest coding would be to generate a square wave signal on the pin, and then set the TRIS based on state of each LED. TRIS would have to be set every time you change the state of the pin in the square wave generating code. That way the LEDs will always be the same brightness. Of course the square wave signal would have to be interrupt driven off of a timer in order to have both LEDs on at the same time.
    Tim Barr

  15. #15
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Square wave sounds more difficult than Dave's code, and any square wave will light up both LED's on a two led with 1 output scenario. And Jumper just wants one, or none to light at a time.
    Last edited by ScaleRobotics; - 14th July 2010 at 17:52.

  16. #16
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scalerobotics View Post
    Really? Because I am using Dave's code on a 18F26J50 (3.3 volt) with no resistors, and it works like a charm. Red, Blue, off
    Attachment 4604
    Code:
    BLINK:  
         HIGH PORTA.0 
         PAUSE 250 
         LOW PORTA.0  
         PAUSE 250   
         TRISA.0 = 1 
         PAUSE 2000    
         GOTO BLINK
    Nice trick indeed.
    How about RED and BLUE = ON ?

    (without ".....Of course the square wave signal would have to be interrupt driven off of a timer in order to have both LEDs on at the same time. " )
    Last edited by sayzer; - 16th July 2010 at 12:24. Reason: typo
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  17. #17
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    Nice trick indeed.
    How about RED and BLUE = ON ?

    (without ".....Of course the square wave signal would have to be interrupt driven off of a timer in order to have both LEDs on at the same time. " )
    Nice one Sayzer! I guess that is four states for one pin!

  18. #18
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scalerobotics View Post
    Nice one Sayzer! I guess that is four states for one pin!
    Yes, the four states can be obtaind with only one pin. Very nice!

    Now, if you use the red-green LED that I mentioned above a cool project can be made.

    http://futurlec.com/LED/LED3RG.shtml

    Since red + green = yellow, then with only one pin in the MCU we can obtain four different states in the LED: off, red, green, or yellow. Also, by varying the percentage duty cycle of the square wave different shades of yellow can be obtained. I haven't tried this yet but it might be a cool project.

    Robert

  19. #19
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Talking

    RED and BLUE = ON

    The only way I can think of is to connect them in parallel. (if serial, 3.3V will not go through)
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  20. #20
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    RED and BLUE = ON

    The only way I can think of is to connect them in parallel. (if serial, 3.3V will not go through)
    No, that's not what I meant.

    If you apply a square wave to this red-green LED, the colors will change so quickly that it will look like it is yellow. I haven't tried it yet, but I'm pretty sure it will look yellow to your eyes.

    Robert
    Last edited by rsocor01; - 17th July 2010 at 12:51.

  21. #21
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Hey Robert,
    Can you give some example code for how the square wave method would work?
    Say you have something like the sliding door app.
    Green = full open
    Red = closed
    OFF = inbetween
    Yellow = moving
    Dave
    Always wear safety glasses while programming.

  22. #22
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Hey Robert,
    Can you give some example code for how the square wave method would work?
    Say you have something like the sliding door app.
    Green = full open
    Red = closed
    OFF = inbetween
    Yellow = moving
    Mackrackit,

    I'm going to order this part and test it to see if it works. The square wave is just a simple 50% duty cycle wave. By using the circuit provided by Scalerobotics, then if the square wave is low the red lights up and if the square wave is high then the green lights up.

    A rapid changing of colors red -> green -> red -> green -> .... would appear to be yellow. It is just an optical illusion. Remember that I talking about a red-green LED with both colors in the same LED casing. Still, I would need to test it to see if it works.

    Robert

    Name:  dual-led3-3.JPG
Views: 2000
Size:  90.2 KB

  23. #23
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Looking forward to see your results, it would be very useful.
    Dave
    Always wear safety glasses while programming.

  24. #24
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Looking forward to see your results, it would be very useful.
    Mackrackit,

    I tested this idea with a red-green 10 LED bargraph and yes it works. The setup is different from what we have been discussing in this thread, but the idea of getting a new color (yellow) is the same.

    First, I applied a square wave to the circuit with a period of 1.2 seconds and you can see how the color changes between red and green. Next, I applied a square wave with a period of 2 milliseconds per cycle (50% duty cycle) and all you see is a yellow color. Also, If you change the percentage of the duty cycle you get different tones of yellow. This would be very useful for a project like the sliding doors.

    Robert


  25. #25
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    COOOL!!!!!

    I can think of several places where that will come in handy.
    Looks like it would make a good article for the wiki. Add a bit of code and schematic for basic use....
    Dave
    Always wear safety glasses while programming.

  26. #26
    Join Date
    Jun 2005
    Location
    Up the bush, Western Plains, NSW Au
    Posts
    216


    Did you find this post helpful? Yes | No

    Default 2 leds 1 pin

    Tried this on my Breadboard, works a treat.
    Hmmm....have to work out how to ad a JPG to this...
    BRB


    Ah, there it is, I hope. I know it means 2 extra LEDs, but that's gotta be cheaper than changing the PIC or messing around with the power supply.
    With the pin as an input, the 5 volt rail is not enough to turn on any of the leds, but setting the pin Hi or Lo the voltage is enough to turn on 2 of them. Also no current drawn during the Input stage.
    Attached Images Attached Images  
    Last edited by muddy0409; - 18th July 2010 at 10:39.
    Peter Moritz.
    Up the bush, Western Plains,
    New South Wales,
    Australia.

  27. #27
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default

    Jumper,

    What does the rest of your circuit look like?

    Regards, Mike

  28. #28
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Add a bit of code and schematic for basic use....
    Ok.

    I attached the schematics to this post. The code is pretty simple. It uses only one pin in the PIC to create four states in the red-green LED. You can get Red, Green, Yellow, or the Off state in the LED using only one pin. Of course, for getting the last state (Off) all the credit goes to mackrackit. He figured that one out .

    Code:
    START:
    
    HIGH PORTB.0                 'Turn on red light
    PAUSE 2000 
    
    LOW PORTB.0                  'Turn on green light  
    PAUSE 2000   
    
    FOR I = 1 TO 2000            'Obtain a yellow light
       TOGGLE PORTB.0
       PAUSE 1
    NEXT I
    
    TRISB.0 = 1                  'Turn off LED
    PAUSE 2000 
       
    GOTO START
    Name:  LED-Schem.jpg
Views: 2347
Size:  14.1 KB

  29. #29
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    I vote for Muddy0409's except, I would put a resistor in series with the processor output lead to limit the output current. This is exactly what I would have proposed except I would have used a couple of zeners instead of the extra led in each leg... If you have an extra inverter available you could modulate one side of a bidirectional led (red/green) and connect the other side thru a resistor to the processor output pin and then place it either high or low and finally to an input state to shut it off.....

    Dave Purola,
    N8NTA

  30. #30
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Referring to the attachment 2 posts above,

    Am I just missing something? by my calcs, assuming 2V drop for the LED's the current would be 3/10000 = .3mA.

    Will this be enough to light the LED? By my calcs, I would think 150-200 ohms would be more suitable. Any help to clear this up for me?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  31. #31
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I don't think the attachment 2 posts above will do any good with 10k resistors.

    I had actually started making a flash demo for this when it first started, but with so many options it got too complicated.
    I really think the correct theory is in the link from post #13 though. The link is also in the flash below ... under the title. (batsocks.co.uk/ ....)

    I only made it through simulating +5V. Things are clickable in the image below ... try it.
    At +5V the resistor is 100 ohms (with 2 diodes).
    But if your situation is different, perhaps I can add to it. ...

    <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH="723" HEIGHT="800" ><PARAM NAME="MOVIE" VALUE="http://www.pbpgroup.com/files/2LED/2LEDS_1PIN.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="truSe"><PARAM NAME="QUALITY" VALUE="high"><EMBED SRC="http://www.pbpgroup.com/files/2LED/2LEDS_1PIN.swf" WIDTH="723" HEIGHT="800" PLAY="true" LOOP="true" WMODE="opaque" QUALITY="high" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>
    Oh, it says I attached the .dsn file ... I didn't, cause it wasn't done.
    But if you have Proteus, I will make it work for all conditions ...
    DT

  32. #32
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Wow!!

    Thanks Darrel. That is an awesome gadget. Is there any way to get you to replace d2 and d3 with variable resistors (or fixed if need be) and bypass the 200 ohm on the pin? This way it will be closer to the other circuit. I would love to test it (and yes, I am trying to use your sim instead of my breadboard) I think a more approiate value would be 0-1000 ohms. If not, its all good.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  33. #33
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Well, the problem with that ... is that the variable resistors would only control current.
    But the correct operation of the LED's depends on the voltage.

    If the total forward voltage of the LED's is less than VDD, both LED's will be ON no matter what the resistor values are. The only difference will be their brightness.

    Given a specific VDD voltage, LED color (V forward) and foward current, the correct configuration can be found.

    And to add 2 variable resistors to the flash demo, would increase the frames from ~50 to more than 500,000. I'm affraid that will take a few years to create, and you probably won't wait the 2 weeks to download it.
    I suppose it could be done more efficiently.

    But again, if you have Proteus, it's a "Piece of Cake".
    DT

  34. #34
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    thanks darrel, once again, it seems a case of I know not what I ask. Don't worry about the demo then. As for the actual circuit, I will have to mull over why the 2 resistors in series with the led's doesn't create a voltage divider.

    I would just LOVE to have proteus. I tried looking it up 1 time, seems it was in the 4 digits, just a little much for me
    Last edited by cncmachineguy; - 9th November 2010 at 03:59.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  35. #35
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Actually, I'd rather know your conditions and do the math.
    What is it you need to do with your LED's?
    VDD, LED Forward Voltage / Forward Current?
    See if the theory works?

    Quote Originally Posted by cncmachineguy View Post
    ... As for the actual circuit, I will have to mull over why the 2 resistors in series with the led's doesn't create a voltage divider.
    Because the voltages across the resistors are changed by the voltage drops that are controlled by the LED's.

    I would just LOVE to haave proteus. I tried looking it up 1 time, seems it was in the triple digits, just a little much for me
    That's what I thought too at first.
    But they have a $250 "starter version" that gives you a 12F, 16F and an 18F.
    Of course it comes with all the other logic chips, analog stuff and test instruments.

    Even if it's not the exact chip you target, the "Family" is usually close enough to know your program has a chance.

    Beware:
    Once you get used to it ...
    You probably will spend $1000 for the full PIC version.
    DT

  36. #36
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    The LED's will be board level indicators, showing drive enables, disabled, or in a fault
    red is 2Vf @ 10-20ma green is 2.2Vf @ 10-20ma

    Vcc 5V

    Now I could use 3.3Vsupply for the LED's But was trying not to add that.

    $250 I could deal with, its the beware I am listing too!
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  37. #37
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Yes, after I posted that attachment I realized it was wrong. The correct value for the resistors should be between 100 and 330 ohms depending on the brightness that you want. I'm sorry for the confusion.

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  38. #38
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    I am using this technique with 6K8 resistors on 3.1V/1500mcd LEDs.
    Vdd is 5.0V.

    I am using one pin to simulate TX and RX transmission with two LEDs inside Hserin and Hserout routines.
    The light level is more than good enough for the purpose.
    I am %100 satisfied with the result.

    __________________________
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  39. #39
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default did some tests today

    here was the setup:

    5Vdc->R1->2.2vF LED->1.9vF LED->R2->GND
    R1=R2
    first tried 240 ohm, Great brightness for each, pretty bright with no input
    next up 1K, simular results just dimmer
    last 4.7K, No real output for off, bright enough to see with input, but not really enough for an indicator in this app.

    So my opinion is everybody in this thread is correct in some respect.

    I feel like the best solution is to use a 3.3V supply. that way there is NO way to light both, and each can be nice and bright. Now, question for the masses: can we use a voltage divider to get this 3.3 from 5? This seems to me to be the least costly answer. Just 2 resistors and off we go. Hang a resistor inline with the signal pin and life is good. My perticular application will have 6 sets of LED's so if 1 from each set were on at once, could be 120mA.droping 1.7 volts, that would be 1.7*.12=.2W. That part doesn't seem too bad. Of course they could be strobed so there would never be more than 1 on at a time, then it would be 1.7*.02=.034W
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  40. #40
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    can we use a voltage divider to get this 3.3 from 5?
    And run the whole thing? Nope.

    Using 5 volts with 470 resistors the thing I posted works fine.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts