It does click, I think what was happening was when I tested it originally I didn’t have a hard back so when I pressed it it wasn’t always clicking, it was pinching the back toward the dome if that makes any sense, when I placed it on a hard surface and tested it it was more uniform,
the lower values were a much tighter range with a pronouced dead band between the key values;
the last five overlap quite a bit which confuses me, it would make sense if the last four overlapped, the last row resistor would need to be adjusted; I figured this all out in a spreadsheet, and granted the resistor values varied some from the color code, but that was a idealized example, that said, I still would expect the values to be more separated. I may need to tweak some values, I suppose it could just be the last row, the overlap on the “menu” button might be due to the “.” button’s overlap
sometimes just writing this all down make things make more sense, I’ll probably just put a trimpot in series with the last row resistor to see If increasing that will make a big difference. but with overlap on all the last five it still confuses me; I’ll try tweaking the 1.2 k value which confuses me as I went from 3x4, to 4x4 adding the 1.2k. if it were that one, I would have guessed it would throw off a column, not a row as it is.
below is the layout of the keypad and the values I got on serial monitor, I pressed the button numerous times for varying duration and then took the highest and lowest values.
5v
|
1k
|
1 2 3 enter
|
820
|
4 5 6 erase
|
1k
|
7 8 9 menu
|
1.2K
|
. 0 - +
A0 – 180 ----- 670 ------ 3.3K ------- 14.8K -------Gnd
1 39 - 51
2 80-91
3 117-136
enter 139-178
4 181-196
5 277-309
6 356 - 411
erase 424-503
7 510 - 531
8 599-674
9 745-773
menu 792-833
. 745-829
0 749-911
A few other things I’m curious of- when is the value It reads evaluated against switch/case conditions; is it the first value it puts out, is there a way to delay it’s reading by a few millisecond while it normalizes some; it seems the most extemely off the values is the first and last values read in the serial monitor,
If I program in a dead band between the closer values, when I press a button and the value reads within that band and outside that band will it still read the value when it is outside the band
for example between 6 and erase and erase and 7 there is little slack, but every time I pressed the button it would always show values outside the area I plan to exclude for example between erase and 7 there is only about 7 values, if I widen that gap in my cases to 20 in case it decides to overlap in the next thousand times versus the 20 or so times I pressed it. the only time the values could be confused were the first and last values it showed on serial monitor. but in all the button presses it always returns a value squarely within the ranges at least for the lower values (not the last five that need hardware tweaking not software)
I’ll try these things but this is new to me.
another thing that puzzles me is when I tried attaching an lcd that would output the value as it was pushed; It only seems to display the value once. and I need to reset it to get it to read the next key press
I’m missing some thing, but am not sure what. any insight would be much appreciated
-carl
char keypressed = 0;
int keyboardPin = 0; // Analog input pin that the keypad is attached to
int keyboardValue = 0; // value read from the keyboard
int k = 0; //
int kbvalue = 0;//
int kbv = 0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
void setup(){
Serial.begin(9600);// hardware serial to PC
lcd.begin(16, 2); //sets up columns and rows
}
void loop()
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue, DEC);
delay(200);
lcd.setCursor(0,1);
keyboardValue = analogRead(keyboardPin); // read the keyboard value (0 - 1023)
while (keyboardValue < 25)
{
//do nothing until a key is pressed
keyboardValue = analogRead(keyboardPin);
delay(50);
} //end of do nothing till a key is pressed
int k = kbValue(keyboardValue); // maps the value of the key being pressed "keypressed" i.e. 0-9
Serial.println(k); // print the value back to the Serial view window on your PC
delay(1000);
}
// interpret the keyboard routine
int kbValue(int kbv)
{
if (keyboardValue <=25)
{
delay (30);}//debounces keypress; does nothing until a key is pressed
else if ((keyboardValue >25) && (keyboardValue <=68)){keypressed = 1;}
else if ((keyboardValue >68) && (keyboardValue <=108)){keypressed = 2;}
else if ((keyboardValue >108) && (keyboardValue <=153)){keypressed = 3;}
else if ((keyboardValue >153) && (keyboardValue <=179)){keypressed = 'enter';}// a key
else if ((keyboardValue >179) && (keyboardValue <=225)){keypressed = 4;}
else if ((keyboardValue >225) && (keyboardValue <=325)){keypressed = 5;}
else if ((keyboardValue >325) && (keyboardValue <=415)){keypressed = 6;}
else if ((keyboardValue >415) && (keyboardValue <=508)){keypressed = 'erase';} //b key
else if ((keyboardValue >508) && (keyboardValue <=560)){keypressed = 7;}
else if ((keyboardValue >560) && (keyboardValue <=680)){keypressed = 8;}
else if ((keyboardValue >680) && (keyboardValue <=773)){keypressed = 9;}
else if ((keyboardValue >773) && (keyboardValue <=834)){keypressed = 'menu';} // c key
else if ((keyboardValue >834) && (keyboardValue <=898)){keypressed = '.';} // menu key
else if ((keyboardValue >898) && (keyboardValue <=945)){keypressed = 0;}
else if ((keyboardValue >945) && (keyboardValue <=970)){keypressed = '-';} //enter key
else if (keyboardValue >970){keypressed = '+';} //d key
switch(keypressed){
case 0:
lcd.print(0);
delay(250);
// do 0
break;
case 1:
lcd.print(1);
delay(250);
// do 1
break;
case 2:
lcd.print(2);
delay(250);
// do 2
break;
case 3:
lcd.print(3);
delay(250);
// do 3
break;
case 4:
lcd.print(4);
delay(250);
//do 4
break;
case 5:
lcd.print(5);
delay(250);
// do 5
break;
case 6:
lcd.print(6);
delay(250);
// do 6
break;
case 7:
lcd.print(7);
delay(250);
// do 7
break;
case 8:
lcd.print(8);
delay(250);
// do 8
break;
case 9:
lcd.print(9);
delay(250);
// do 9
break;
case 'a':
lcd.print("a");
delay(250);
// do a
break;
case 'b':
lcd.print("b");
delay(250);
// do b
break;
case 'c':
lcd.print("c");
delay(250);
//do c
break;
case 'menu':
lcd.print("menu");
delay(250);
// do menu
break;
case 'enter':
lcd.print("enter");
delay(250);
// do enter
break;
case 'd':
lcd.print("d");
delay(250);
// do d
break;
}
while (keyboardValue >=25); //wait until key no longer being pressed before continuing
return keypressed;
}