Interlocked buttons with clear troubleshooting

@machambers

To be clear, you have momentary contacts like a pushbutton, and you are trying to do an old school “radio button” type thing.

Press a button, get that station. Press another, switch stations.

And I forget how, but there was a way to get all the buttons to pop out.

Old multi-line telephones had the same thing.

I didn’t look further, but

 arduino radio buttons code

had a crap-ton of plausible links. But you close now, so.

This

while (digitalRead(button2) == LOW);
  delay(50);

Is wrong in several ways, use

    do {
        delay(50);
    } while (digitalRead(button2) == LOW);
  

For your simple denouncing need. You made the while look like it was part of the if/else, the IDE autoformat tool might show you that syntactically it was a separate statement entirely.

And bounces are rapid, best to wait first and then do the checking otherwise you can catch a glitch. In this case it might not make a difference, but.

EDIT: Curiously, IDE auto format curtly informs me "No changes necessary for Auto Format". When I "fix" the code layout by Manual Format, so to speak, it set "finished",having done nothing, and then reports no changes necessary for subsequent Auto Formats.

So Auto Format isn't all it could be or my caffeine hasn't kicked in yet.

a7