i am trying to create a simple 3x3 MIDI controller with an arduino nano, but i have ran into a problem. I want to have 3x3 grid of buttons with backlight, but nano has only 13 digital pins, so using one pin per button and one pin per LED doesn't quite work. I've heard about using analog pins for buttons, but doesn't that limit me to pressing only one button at a time? Or are there any other solutions to drive 9 buttons and 9 LED's at the same time?
2 Answers
The usual solution for keys is to drive each column of keys high and scan the rows whilst the column is high, so you only need 6 pins, 3 to drive columns high one after the other and three pins to see which rows (if any) have a closed key.
For driving LEDS you can use a multiplexer
The trick for using analog pins for buttons is to create a voltage divider:
simulate this circuit – Schematic created using CircuitLab
The voltage on Ain will then depend on which buttons are pressed and the values of the resistors; the number of buttons you can chain together like this is dependent only on the resolution of the ADC.
-
2\$\begingroup\$ The number of buttons in this scheme is also heavily dependant upon the tolerance of the resistor values and the noise jitter of the A/D readings. Both these factors require a value range window to be applied around each detection level. Since these windows cannot overlap this places strict limits on how many windows you can stack into the full available range of the A/D converter. \$\endgroup\$ Oct 10, 2013 at 13:05