Jason Wolfson wrote: --------8<-------- >>Does anyone have any clever, low parts count >>methods of multiplexing 3 pushbuttons onto >>2 port pins? --------8<-------- Then Philip Martin replied: --------8<-------- >Easy, > >Switch one connects to pin one. >Switch two connects to pin two. > >Switch three connects to both pin one and two, each connection via an >IN4148 diode. --------8<-------- The problem with this (which may not be a problem, depending on the application) is that you can't distinguish between switch 3 being pressed vs. switches 1 & 2 being pressed simultaneously. Without some kind of lockout circuitry in the encoder, there's no way to do this with just a diode/resistor matrix alone. That being said, you might be able to do something using diodes & pullup resistors in conjunction with time multiplexing code to sort out which switch (or combination) is being pressed. It would go something like this: B0, B1 are the I/O pins, SW1-SW3 are the switches. SW1 is connected between B0 & B1 with its diode D1 in series, and SW2 its diode D2 are connected antiparallel. SW3 is connected to both B0 & B1 through two steering diodes, D3 & D4: Vcc SW3 | __I__ R1 + | | +---o o---o----D3----o--------o----------o-------| B0 | | | | | R3 | SW1 | o SW2 | o | | | -| -| | Gnd | | o | o | | | | | | Vcc |+ | | | | D1 D2 | | R2 | |+ | | + | | | | +----D4----o--------o----------o-------| B1 | To read the status of the switches, you must set the TRIS & data bits so as to cycle B0 and B1 through the following three states: B1 B0 Meaning --------------------------------------------------------- State 0 out low in high Neither SW2 nor SW3 pressed out low in low SW2 OR SW3 pressed State 1 in high out low Neither SW1 nor SW3 pressed in low out low SW1 OR SW3 pressed State 2 in low in low SW3 pressed in high in high No switch pressed Just a little more work will allow you to figure exactly which switch is pressed. Note: I haven't tested this, but it seems as if it should work. No doubt others will spot any errors or shortcomings. --BN ---------------------------------------------------------------------------- Country Robot "Modular robot components 69 S. Fremont Ave. # 2 for education and industry" Pittsburgh, PA 15202 ----------------------------------------------------------------------------