EmbeddedRelated.com
Forums

One pin for both an input (switch) and output (LED) ??

Started by Dave Mucha January 30, 2006
Hi all,

I am looking for a way to use one pin for both an input and an output.

An LED is the output. and a switch would be the input.

I can see a few ways to have both on one pin, but not sure if there is
a preferred way.

It seems the simplest way is to have a resistor, and LED and a switch
all in series.  then pull the LED-switch line down to power the LED,
then monitor the voltage to test the switch condition.

Is there a better way ?

Any ideas ?

Dave
	
--- In piclist@picl..., "Dave Mucha" <dave_mucha@y...>
wrote:
>
> Hi all,
> 
> I am looking for a way to use one pin for both an input and an 
output.
> 
> An LED is the output. and a switch would be the input.
> 
> I can see a few ways to have both on one pin, but not sure if 
there is
> a preferred way.
> 
> It seems the simplest way is to have a resistor, and LED and a 
switch
> all in series.  then pull the LED-switch line down
to power the 
LED,
> then monitor the voltage to test the switch
condition.
> 
> Is there a better way ?
> 
> Any ideas ?
> 
> Dave
>
Unfortunately the only way to get the led to light in that case is 
to have the switch always made, which means a limiting condition 
that the switch must be made to make the output device(led) active 
is introduced. It works, but only if you can meet the basic condition

A better way might be to put the led and resistor in series between 
the pic pin and ground. To turn on the LED set the pic state output-
high. If you put the switch between +V and the pic pin and set the 
pic pin state to input you can read for a high=switch-made. The nice 
thing about that is that the led+resistor act as a pulldown on the 
pin. The disadvantage is that the led lights when the button is 
pressed. Also you can swap the switch for the led+resistor if you 
want to change from active high to active low.(as long as you change 
the output state of the pic pin for when you want the led to light)

Chris Barron
	
--- In piclist@picl..., "Chris" <fixitsan@a...> wrote:
>
> --- In piclist@picl..., "Dave Mucha" <dave_mucha@y...>
wrote:
> >
> > Hi all,
> > 
> > I am looking for a way to use one pin for both an input and an 
> output.
> > 
> > An LED is the output. and a switch would be the input.
> > 
> > I can see a few ways to have both on one pin, but not sure if 
> there is
> > a preferred way.
> > 
> > It seems the simplest way is to have a resistor, and LED and a 
> switch
> > all in series.  then pull the LED-switch line down to power the 
> LED,
> > then monitor the voltage to test the switch condition.
> > 
> > Is there a better way ?
> > 
> > Any ideas ?
> > 
> > Dave
> >
> Unfortunately the only way to get the led to light in that case is 
> to have the switch always made, which means a limiting condition 
> that the switch must be made to make the output device(led) active 
> is introduced. It works, but only if you can meet the basic condition
> 
> A better way might be to put the led and resistor in series between 
> the pic pin and ground. To turn on the LED set the pic state output-
> high. If you put the switch between +V and the pic pin and set the 
> pic pin state to input you can read for a high=switch-made. The nice 
> thing about that is that the led+resistor act as a pulldown on the 
> pin. The disadvantage is that the led lights when the button is 
> pressed. Also you can swap the switch for the led+resistor if you 
> want to change from active high to active low.(as long as you change 
> the output state of the pic pin for when you want the led to light)
> 
> Chris Barron
>

The LED being ON or OFF when the switch state is changed is not a
problem.  the switch will be momentary so the LED going ON (or staying
ON) would be acceptable.

Dave