Hardware Input/Output

1 wire LED and switch

Wagner Lipnharski of UST Research Inc. says:

An easy way to have a key and a indicator led connected to a single microcontroller port pin is connect the LED (anode) with a resistor (330 Ohms) to +VCC (+5Vdc) and the cathode to the port pin, the key goes to the same port pin to ground via another resistor (100 Ohms). By this way, whenever you want to read the key, just flip the port pin to up level and read it. The LED can serve as an indicator of the function selected by the key. Suppose the LED is off (port pin high), pressing the key will turn on the LED (3/4 brighness) and will drop the port pin level, reading the port pin would indicate a low level, so it would means "key pressed", then your software will "latch" that information flipping the port pin to low level (LED goes to 100% brightness) indicating key was read as "pressed". A 49ms low level and 1ms high level to read the key is enough to keep the LED as brigh as possible and run the debounce routine. After the debounce, pressing the key again would signal the software to deactivate the LED. It would works as a flip-flop switch with indicator, with a single port pin. The 100 Ohms resistor (that creates the 3/4 LED intensity) is to inform you when the software effectivelly read the key pressed and confirmed the "pressed" status by bypassing the 100 Ohms resistor to ground.

Interested:

Questions: