Multiple pushbuttons on one pin using adaptive ADC
NOTE: This concept has been improved quite a bit since this original post was made. Go to the end of this thread for the latest.
I made a circuit and technique for reading 4 separate buttons independently over a single P2 pin using the ADC and the 'count-highs' smart pin mode.
I hope you can see that.
Here's my board. I ganged 1K resistors to get the various values. You could get by with two SMT 4-pack resistors of R and 4R values, for practicality:
An ADC is used to read the states, which are non-linear:
I didn't want to have the ADC need any complex scale+offset calibration, so I made an adaptive sampler that starts off in the ballpark and then homes in on the number of clocks that it takes to get a 'VIO minus GIO' delta of 3300, which results in direct millivolt readings for the 'PIN minus GIO'. Now we get good data without anything more than ADD/SUB. This would only work for one pin at a time, since each pin would need a slightly different number of clocks to get the VIO-GIO delta of 3300.
Here is some DEBUG data, as I cycled through all the pushbutton-press combinations:
And here is the code: