Electronic Radio buttons - feasible approach?

For part of an upcoming project I want to create a user interface the include radio button using LEDs and tact switches. Radio buttons are groups of buttons that allow the selection of mutually exclusive choices whilst simultaneously showing which choice is currently selected. They are a staple of graphic user interfaces, but originally started as mechanical interlock type switches on radios (hence the name).

A simplistic implementation would have an input for the switch and and output for the LED, using a lot of I/O. I think I can cut this requirement in half by doubling up each digital I/O as a both an input and an output. I have attached a schematic for the circuit.

When a choice is not selected, the Arduino pin is set as INPUT_PULLUP, waiting for the tact switch to be pressed. The current choice is set as OUTPUT and HIGH, so that the LED is on. When a new choice is detected, the current choice is set to INPUT_PULLUP and the new choice to OUTPUT and HIGH.

As only one LED is on at any time, only one resistor is used for all the LEDs. To prevent a dead short when a user (re)selects the current choice, a 1k resistor is used.

I have prorotyped the solution on a breadboard and have written software that does the I/O detection and management. It all seems to work ok, but my questions to the collective intelligence is

  • whether there are longer term bad effects to doing this sort of thing?
  • are there better ways of achieving the same result?

You could also do it with a matrix keypad, and a set of neopixels or LEDs on a shift register, and do all the tracking in software.

And if you press two at a time.

And if you press two at a time.

Simultaneously pressing more than one - last one you let go wins. This is actually the way the mechanical ones work as well.

There are a number of ways to get one pin to read multiple buttons. Consider a series resistor arrangement wired between 5 v. and gnd. say four 10 K resistors. Then attach your pushbuttons at the three intermediate positions of the divider, and wire them all to a single analog pin. By reading the possible voltages, you distinguish the switch pressed. The reason not to attach buttons at the end position of the voltage divider (5 v. and ground), is to avoid an inadvertent short if multiple buttons are simultaneously pressed.