Thanks for that. One is never too old to learn new tricks :-) I have shared LEDs and switches on a pin but only in circumstances where having the LED illuminate when the switch closes is acceptable - range changing on instruments for example On 22 April 2014 09:51, IVP wrote: > > The trick for using a single pin or a LED and a switch seems to > > have passed me by. Could you explain it to me? > > The output drive current for an LED is a lot more than the current > needed to detect a switch closure > > Imagine 330R + LED to ground from the pin. When the pin is driven, > as an output, the LED lights > > Also connected to the pin is a high-value resistor, eg 47k, as a pull- > down to ground and eg 10k to one terminal of a switch, the other > terminal of the switch going to Vcc. A pair of values that will pass as > a logic '1' when the switch is closed. It's possible that the LED and > its resistor may also be a pull-down but I can't vouch for that. > > You might set up a 500Hz timer interrupt. Every 100th interrupt the > pin is changed from an output to an input and the level on the pin > noted. If it's high, then the switch is closed. If it's low then the pull= - > down is in effect. The LED will go off or dim for that 2ms, which > would not be noticeable. As all the components involved have little > capacitance, the latencies should be short enough to be insignificant. > > On the next interrupt the pin is changed back to an output, with > whatever state the LED is meant to be on. If the switch is still > closed and the LED is meant to be off, the weak current through > the 10k won't be enough to overcome the driven logic '0' > > Joe > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 __________________________________________ David C Brown 43 Bings Road Whaley Bridge High Peak Phone: 01663 733236 Derbyshire eMail: dcb.home@gmail.com SK23 7ND web: www.bings-knowle.co.uk/dcb --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .