Very Brief Overview:
The AVR's digital inputs are Schmitt-Triggered, allowing for slowly rising/falling and/or noisy "edges" to be "cleaned up" into sharp 0->1 or 1->0 transitions. The threshold-voltages for each transition differ, but are quite stable, thus slowly-changing transitions are relatively immune to noise.First, set the pin as an output to charge the capacitor.
Next, switch the pin to an input and measure the time it takes for the capacitor to discharge.
The code has been developed specifically to improve noise-immunity and to reduce CPU-waiting *dramatically*, via either Blocking or Non-Blocking methods, which can be called repeatedly from the main 'while()' loop.
This, like all my projects, is ongoing... It's currently at version 0.50-9. There's always room for improvement, and it's used as a piece of many of my other projects. (e.g. audioThing)
(In the picture, a Nokia Phone's main PCB has been stripped of all its components, revealing solder-pads for the rows/columns in its matrix-keypad. Resistors were soldered to these pads, as shown in the schematic, atop Kapton tape to insulate them from the PCB.)
This system *definitely* depends on your circuitry-characteristics... When a button is pressed, the system detects which button based on thresholds on time and voltage, both analog values... It works fine in my lab-environment, but may be questionable in other environments.
Some things that affect its measurements:
* AVR clock-frequency
* Quite possibly different AVR Chips with the same part-number will respond differently, due to slightly-different threshold voltages...?
* Large variances in AC electrical-noise...
(6-16-15) #Analog Input Hack: Push Button Encoder looks like it could be a pretty clever usage.
(6-20-15): Non-Blocking Capacitive Sensing (Disco Dance Floor)... dunno why I never thought to use this with capacitive sensing. Seems doable.