@OOO
I think your approach is interesting and am looking forward to seeing it work.
You need to avoid reading the button/led that you have already turned on.
Maybe something like this (compiled but not tested)
/*
"Radio Buttons"
When a button is pressed, latch its own LED on, and turn all the others off
*/
const int nButtons=3;
int buttons[]= { 7, 12, 14 }; // each "button" is a button/led pair
int currentOn = 0;
void latch( int onPin)
{
// turn onPin on,
digitalWrite( onPin, LOW);
pinMode( onPin, OUTPUT);
// if there is an other pin on, turn it off
if (currentOn > 0)
{
pinMode( currentOn, INPUT);
digitalWrite( currentOn, HIGH); // pullup
}
}
void loop()
{
for (int i=0; i< nButtons; i++)
{
// read all but the currenly-on button
if ( buttons[i] != currentOn && digitalRead( buttons[i])== LOW) // active LOW
{
latch( buttons[i]);
currentOn = buttons[i];
break;
}
}
}
Cheers,
John