On Mon, Sep 24, 2001 at 01:57:43PM +1000, David Duffy wrote: > Dave wrote: > >I am wondering if it is possible to multiplex a push button switch > >input and an LED output on the same I/O pin. My idea is that since > >the switch input only needs to be sampled every 2ms, it can be set as > >an output for an LED when not sampling the switch. Also, when the pin > >is switched to input to sample the switch, the time taken to do so is > >so minimal, that the LED would not even flicker. I figure the I/O pin > >only needs to be set as an input for just a few assembly instructions. > >Hardly noticeable, right? > > > >So, I've got a couple questions. First off, is the idea described > >above even possible? And finally, what would the resulting circuit > >look like? I've come up with this: > > > > LED R1 > > +--|<|--/\/\----o +5V > >-----+ | > > I/O | | > > Pin +-----+ > > | | \ > >-----+ | \ > > +--/\/\--+ +--o Gnd > > R2 SW1 > > > >However, I cannot seem to come up with R1 and R2 values that work when > >the switch is closed, and the pin is setup as an input. > > Yes, this will work just fine if you delete R2 and make R1 about 330R. > Use the TRIS register to put your i/o pin into the hi-impedance state > to read it. Leave the i/o bit cleared when as output to make it like an > open-collector output in parallel with the switch. I do this all the time. > The LED will illuminate whenever you press the switch but in most > applications this is not really a problem. Call it an LED test feature! Hmm... thanks for the suggestion, but I really wanted to keep the LED independent from the switch. In this application it's not possible to have the LED turn on and off with the switch. Is this possible? -Dave -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.