Button box wiring sanity check

I am building a flight sim button box and i would like someone to please check my proposed wiring diagram, I will be using 12 buttons, 4 rotary encoders, each also with a push button and 4 (on)-off-(on) toggle switches as well as one additional toggle switch to use as a modifier for the buttons.

Any comments or suggestions appreciated.

Without diodes at each cross point you risk pressing 2 buttons and shorting out 2 outputs to each other, in turn risking damage to the output driver.

I have bought diodes and will be adding them into the matrix.

So 4 of those red pushbuttons actually represent the pushbuttons built into the rotary encoders?

I found it quite difficult to make rotary encoders work smoothly without using interrupts. On Leonardo, these are pins 0, 1, 2, 3, 7. But you only need one interrupt pin per encoder. The other encoder line can be an ordinary digital input. Remember, on Leonardo, it's OK to use pins 0 & 1, unlike on Uno.

PerryBebbington:
Without diodes at each cross point you risk pressing 2 buttons and shorting out 2 outputs to each other, in turn risking damage to the output driver.

I agree about using diodes, but that is for preventing "ghosting" where buttons appear to be pressed when they are not. The way I would write the code is that only one pin would be an output at any time, so no risk of shorting (unless a coding error is made, in which case diodes won't prevent a short anyway). In my code idea, each column in turn would be OUTPUT+LOW, while the other columns would be INPUT (to make them high impedance, they won't be read). All rows would be INPUT_PULLUP at all times.

Paul, good idea! I've never actually built anything requiring me to scan buttons.

The keypad.h library does the same to scan a button matrix.
One output, say column 1, is driven low, then the inputs with their internal pullups are read. Any returning a LOW are the pressed button(s). The other columns can be left as inputs with internal pullups so no chance to short a HIGH output and cause damage anywhere.

chincb:
4 (on)-off-(on) toggle switches

Are those momentary, and spring back to centre? if so, you may not need the diodes, as long as you won't be pushing more than one switch/button at the same time. Or can they be left in 3 positions? If so, you will definitely need those diodes.

CrossRoads:
One output, say column 1, is driven low, then the inputs with their internal pullups are read. Any returning a LOW are the pressed button(s). The other columns can be left as inputs with internal pullups so no chance to short a HIGH output and cause damage anywhere.

Actually, if the pin is written LOW, you can leave it LOW and set it to INPUT as you do not need INPUT_PULLUP. It will then be LOW the next time you set it to OUTPUT and should compile to less code.

If the compiler is correctly written - and I certainly hope it is - setting INPUT_PULLUP should first set as INPUT and then write the pin HIGH (whether or not it is already). Setting to INPUT should absolutely not affect the output register in any way. :astonished:

you do not need INPUT_PULLUP

I was suggesting INPUT_PULLUP for the rows, not the columns. They can be set INPUT_PULLUP in setup() and left like that.