Small question, one for me to just learn best practice more than anything. If there is a better way to do this please critique :)
Basically I have multiple GPIO inputs that correspond to one button press. So for example, if the user presses button 2, I get High values from pin 5, and pin 6.
So in my code, I need to map the High pins to a "button" id.
To do this, I am using a 2D list where the index of the elements will correspond to the "id" of the button.
buttons = [
[],
[PIN_5],
[PIN_5, PIN_6],
[PIN_6],
[PIN_6, PIN_19],
...
]
I am using a threaded loop to check for pin values, and storing the high state pins in a new list.
So once a button is pressed, a new list will have what pins are high.
pins_high = [PIN_5, PIN_6]
So this is where my best practice question comes in, to map those pins to the button "id" in the mapping list, I am using a try except pass approach
button_pressed = 0
try:
button_pressed = buttons.index(pins_high)
except ValueError:
pass
Is this best practice? It seems to me like a nice neat solution, but am I overlooking any possible leaks/effects of using a try/except/pass like this?
Cheers, Jamie