[sdiy] Reading two buttons with a single IO pin
Ingo Debus
igg.debus at t-online.de
Sun Feb 22 12:01:02 CET 2015
Am 20.02.2015 um 22:16 schrieb Tom Wiltshire:
> I've been considering the question of how to read two buttons with a single microcontroller IO pin. There are various ways to do this.
On some micros the input pins can be programmed to have a on-chip pullup or a pulldown resistor. In this case it's very simple. Connect the input pin via one button to ground and via the other to Vcc. If no button is pressed, the pin reads 0 when pulled down and 1 when pulled up. If the first button is pressed, it reads always 0. If the second button is pressed it reads always 1.
You cannot determine the both-buttons-pressed state this way. If both buttons are pressed at the same time, there's a short circuit, so you'd need a current limiting resistor in series with one of the buttons. It has to be much lower than the on-chip pullup/down resistors so that the logic levels are still ok.
No ADC required, and, except for the current limiting resistor, no external components but the switches.
Ingo
More information about the Synth-diy
mailing list