2 LEDs used Bi-directionally


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,160

    Default 2 LEDs used Bi-directionally

    I'm building a matrix using this idea:
    http://www.picbasic.co.uk/forum/showthread.php?t=14439

    Name:  Bi-directional LEDs.JPG
Views: 563
Size:  51.8 KB

    Pseudo-code:
    Code:
    GP0 TRIS 1     ' Input
    GP1 TRIS 0     ' Output
    GP1 = 1         ' Yellow ON
    
    GP0 TRIS 0     ' Output
    GP1 TRIS 1     ' Input
    GP0 = 1         ' Red ON
    Is that right?

    And how do you turn them both off? Both output LOW?

    Robert

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Check this thread out. You might get some hints...

    http://www.picbasic.co.uk/forum/show...1692#post91692
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,160


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    I had read that thread already, but they were going PIN to VDD/VSS. I'm going PIN to PIN so I have to play with TRIS more. Rereading it did show me TRISx = 1 will turn off LEDs though.

    Setting up the breadboard to test what I have so far. I better change for an old PIC, just in case of magic.

  4. #4
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    TRISx = 1 is used to read an analog input, ex: A/D input. It turns the port into a high impedance input. So, if you want the port to sink in current just make that port low with TRISx = 0 like in the example in that thread.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,160


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    I feel like a retard. So...

    PIN --- DUAL LEDs --- RESISTOR --- 5VDC

    PIN defined as output:

    HIGH will source, turn on outgoing LED (like we always do)
    LOW will sink, turn on incoming LED


    I don't get how I'm to set ports/TRIS at both ends so neither LED will turn on. I've gone through that thread and a few others all evening but I can't see the forest through the trees apparently.


    Quote Originally Posted by rsocor01 View Post
    TRISx = 1 is used to read an analog input, ex: A/D input. ...
    Even if my ports are defined as digital?

    Robert
    Last edited by Demon; - 12th January 2014 at 05:01. Reason: analog VS digital

  6. #6
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Robert,

    In your schematic at the top of the thread... the highlighted (green) LED's will be dark when GP 1&2 are BOTH High OR LOW. But the trick is to keep track of that interaction with the other LED's that are also tied to either of those two pins.

    If GP1 is high and GP2 is low then the Yellow LED will be lit, and vice/versa for the Red one.

    Seems like to me it's time to draw up a good ol'e fashioned truth table.

    With 5 bits (pins) in use it will have 2 exp 5 = 32 possibilities. The truth table will also help you develop your code.

    Is this what they call Charlieplexing?? I've never done one of those, but that is how it seems to my feeble mind.

    good luck
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  7. #7
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Quote Originally Posted by Demon View Post

    Even if my ports are defined as digital?
    TRISx = 1 'Sets the port as analog
    TRISx = 0 'Sets the port as digital

    When TRISx = 1 the port is set to a high impedance input mode, meaning no current in or out for the LEDs. In other word it turns the port off for the LEDs.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,160


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Found my answer to sinking the incoming LED.

    Do I set it as an output then set it's low state?
    Quote Originally Posted by mackrackit View Post
    YUP.

    Think of it like this. LED connected anode to positive rail. To make it light with the cathode connected to a PIC pin you would output LOW. (LED has a drop down resistor)
    ...
    http://www.picbasic.co.uk/forum/showthread.php?t=7638


    PIN --- DUAL LEDs --- RESISTOR --- PIN

    Is it a simple matter of leaving both pins output LOW? That would mean both are connected to ground; no chance of leaking current.

    Robert

  9. #9
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    In regard to the site mentioned in post #1:

    Just to let you know I found the value of the current limiting resistors for the LEDs to be important. Set incorrectly they'd give me ghosting.

    You also have to repeatedly set the TRISIO and the GPIO to get the specific LED or LEDs you want lit. Usually once wasn't good enough.

    If you're in need of more than 20mA per pin I successfully used opto-isolators instead of the LEDs. I don't remember the specific part number but I think I posted that link somewhere. If needed I'll find it and reference it here.

    I'd also suggest you put a switch in the ICSP clock and data lines to isolate the PIC for programming. It will save you alot of time and effort.

    As always good luck and please post program here when finished.

  10. #10
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,160


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    Quote Originally Posted by Demon View Post
    I'm building a matrix using this idea:
    http://www.picbasic.co.uk/forum/showthread.php?t=14439
    ...
    For those of you that are visual and like working with rows and columns like me, I came up with this design:

    Name:  CharliePlex.JPG
Views: 388
Size:  101.9 KB

    You can have a lot more LEDs by using pins across ROWs and COLUMNs, but that adds more complexity than I can handle, and this is good enough for me.

    By using a maximum of 8 pins per side in this configuration, you can use BYTEs and LOOPs to control lighting.

    Robert

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,160


    Did you find this post helpful? Yes | No

    Default Re: 2 LEDs used Bi-directionally

    And this is how I plan to turn the LEDs ON-OFF 1 column at a time:

    Name:  CharliePlex logic.JPG
Views: 402
Size:  66.2 KB

    (in theory, I still have to finish my breadboard)

Similar Threads

  1. 32 LEDs with less than 20mA
    By Demon in forum Off Topic
    Replies: 11
    Last Post: - 23rd January 2014, 03:28
  2. Leds on/off
    By Leonardo in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 2nd September 2009, 21:36
  3. Two LEDs on one Pin
    By modifyit in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 6th June 2006, 13:32
  4. 8 Leds
    By leonel in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 24th June 2005, 22:15
  5. Want some help with LEDs
    By Srigopal007 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 23rd November 2004, 20:46

Members who have read this thread : 0

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