Basically, it's a voltage divider and you know which key was pressed by virtue of the voltage read in to an analog pin.
My question is what is the range (granularity?) I can safely detect? That is, if the voltage range to an analog pin if 0-5V, and I want 15 button, can I safely have no active keypress by 0-0.5V, key 1 to be 0.6 - 0.9, key 2 to be 1.0-1.3, etc.... Or is a range of 0.3 unreliable? (Would I need to divide up the button into 2 sections, using 2 analog pins?)
In general, 15 buttons should be just fine. You have evidently figured out that you use a "comb" function whereby the transition points are calibrated to be halfway between the voltages corresponding to adjacent switches; you do not expect the voltages to match a certain specific value or narrow range.
I dislike the approach due to my experience of the unreliability of this system over time, as I have a number of failed appliances - computer monitors, MP3 players, microwave ovens and such - which use this method and fail over time as the contact resistance of the switches used fluctuates and as they develop leakage with moisture ingress (particularly bad for MP3 players which live in pockets!) leading to incorrect key detection and "ciphers" (where the OSD randomly starts up and drags one or more adjustments to the extreme).
On some occasions however, this appears to be not the fault of the keys, but of leakage in the ASIC (so it persists with the key assembly completely disconnected!) - you would presume the ATmega chips to be of better quality than to suffer that problem.
Use a small capacitor on the analog pin to reduce noise from switch-contacts (10nF to
100nF is appropriate.
Always read the analog pin repeatedly till the voltage stabilises - you don't want to
be confused by a transient voltage change during sampling, nor by contact bounce.
You can assume a repeatability of 5 counts or so if the Arduino's supply is stable
and there's aren't any large noise sources like motors.
With Aref at 5V (default setting) the analog readings will come back in the range of 0 to 1023, with each step representing ~4.88mV.
1023/15 = 68, 68 * 4.88mV = 0.332V.
A string of 15 1K resistors should work pretty well, adjust the analog read break points to match:
Vout = 5v*1000/(1000+14000) = 0.3125V
Vout = 5V * 2000/(2000+13000) = 0.667
Vout = 5V * 3000/(3000+12000) = 1V
Vout = 5V * 4000/(4000+11000) = 1.33V
etc.
val = analogRead(Ax);
if ( (val >=0) && (val <=67){
// button 0
}
if ( (val >=68) && (val <=135){
// button 1
}
if ( (val >=136) && (val <=203){
// button 2
}
// etc
MarkT:
Use a small capacitor on the analog pin to reduce noise from switch-contacts (10nF to
100nF is appropriate.
Always read the analog pin repeatedly till the voltage stabilises - you don't want to
be confused by a transient voltage change during sampling, nor by contact bounce.
In other words, you must "de-bounce" this just as if you were using a digital port. Since you are already using resistors and no key is connected directly to the analog input, a capacitor will provide some degree of de-bounce, but you need to provide a proper routine which performs the "slot" determination each millisecond or so and only when it has determined the voltage to lie within that same "slot" for each of ten successive millisecond samples, judge that to correspond to a valid button press.
Again, you are not expecting to to be the same analog value, but to lie in the same "slot" or range of values.