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?
