The aim is it comes onto a screen saying "How Many Sections?", you then use the keypad to input a number and press a separate button ("buttonEnter") when it will move to the next screen. The Getkey is working but only when you hold the keypad button down and it isn't keeping the number. Where I am going wrong?
Thanks in advance.
I need to be able to type 2 numbers and store them so they can later be saved to a CSV file.
If anyone could help or point me in the right direction I would appreciate it.
It is wired up through resistors to a single analogue pin which works well.
Since that is NOT how the thing is supposed to be wired, or how the Keypad library expects it to be wired, that statement is extremely hard to believe.
You need to read the keypresses INDEPENDENTLY from what the LCD shows. If there is a key pressed, and it is not the "Use this value" key, store the key in the next position in an array, increment the index, and store a NULL in the array. If it is the "Use this value" key, use atoi() to convert the array to a numeric value, reset index to 0, and set the first element of the array to NULL. The LCD display, at the time the "Use this value" key is pressed will define where to store the numeric value.
You don't need the array/atoi - approach, there's an easier way since you're just reading numbers.
Problem 1: If a key has been pressed, you need to wait until it is released.
Problem 2: You need a variable to the pressed keys. If you press another key again, you take that variable, multiply it by ten and add the new value. If you ask why, just have a look on how you type numbers:
3
31
314
Attention: Remember that a int's max value is 32767, so the extra task for you is to make sure that the user does not enter bigger numbers. You may set a limit of 3 digits, for example.
Pseudo Code:
int value = 0;
char key;
while(true)
{
delay(20);
key = KeyPad.getKey();
if (key == NO_KEY) continue;
if (key == ENTER) break;
value = (value * 10) + key;
// TODO: display value here
do
{
delay(20);
}
while (KeyPad.getKey() != NO_KEY); // wait until key is released
}
// TODO: finish. your value is stored in the "value" variable