Shop OBEX P1 Docs P2 Docs Learn Events
Control 2 LEDs with one pin — Parallax Forums

Control 2 LEDs with one pin

Mohamed RefkyMohamed Refky Posts: 47
edited 2008-02-17 22:46 in BASIC Stamp
Hello,
How to control 2 LEDs using one port pin like red and green LED and how to turn off both.

Thank You

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-02-17 18:07
    You could set the common pir to 2.5v and then use high and low to change between them. How to turn them off safely I'm not sure about.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • ZootZoot Posts: 2,227
    edited 2008-02-17 20:45
    If you use a voltage divider with resistors rated for the LED (e.g. 470-1000 ohms) then you can hook a bicolor (2pin) LED up to a single pin. To make it one color, set the pin HIGH, to make it the other color set the pin LOW, to turn the diode OFF, set the pin to INPUT, e.g.:

    
    
    
    
    +5v ---\/\/\---+---\/\/\--- GND
                   |
                   |
                 -----
                 /\ \/
                 -----
                   |
                   |
                  PIN0
    
    
    LEDcolor VAR OUT0
    LEDonoff VAR DIR0
    
    DO
    LEDonoff = 1
    LEDcolor = 1
    PAUSE 1000
    LEDcolor = 0
    PAUSE 1000
    LEDonoff = 0
    PAUSE 1000
    LOOP
    
    
    



    The downside? The circuit will draw current even when the LED is not on (a few MA).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php


    Post Edited (Zoot) : 2/17/2008 8:50:20 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-02-17 22:32
    The attached circuit can be used to minimize the quiescent current draw. The idea is to add enough diodes that the sum of all the forward voltages is greater than 5V. On my bench, using a red and a green LED, along with four 1N4148-type diodes having a 0.575V forward voltage, I measured an 8µA quiescent current. When the input is high, the lower LED will light; when low, the upper LED comes on; when tri-stated, neither one illuminates. You can also light both LEDs at once, albeit at half brightness, using FREQOUT, as the following program shows:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    DO
      LOW 8                 'Top LED on.
      PAUSE 1000
      FREQOUT 8, 1000, 60   'Both LEDs on.
      HIGH 8                'Bottom LED on.
      PAUSE 1000
      INPUT 8               'Both LEDs off.
      PAUSE 1000
    LOOP
    
    
    


    -Phil
    153 x 306 - 2K
  • ZootZoot Posts: 2,227
    edited 2008-02-17 22:46
    PhiPi -- one can learn something new every day. That's good. I like that. I may have to rewire a little 4 (bicolor) LED display I have that runs from 4 Stamp pins.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.