utilizing a 74HC4051 to multiplex inputs

for my next project (which is going to be a neat little pedal-controlled sample-based instrument – more about that later), i will need to know the states of lots of buttons, but utilizing as little as possible of arduino’s pins. using shift registers for this purpose came directly to my mind, but then I had a look at the schematics of the pocket piano arduino shield from critter and guitari. they used  74HC4051 8bit-multiplexers to read the buttons which seemed to me to be a safer way to get the button states right. besides, if you need to multiplex more than 8 inputs, you can save input pins by using multiplexers: for each shift register you attach to the arduino, you need two pins (clock and input), for the first multiplexer you always need 3 pins (output to select the outputted bit), but for every additional multiplexer you need only one more input pin!

today i tried the multiplexers and made up a small code snippet, which scans though all inputs of the 74HC4051s and outputs the numbers of the active inputs via serial. with a little bit twiddling it got quite short:

Continue reading “utilizing a 74HC4051 to multiplex inputs”