so i want to work with the 12 button keypad from sparkfun. i know that there are a lot of tutorials explaining it but none really cover taking four seperate inputs from the keypad and turning them into a string that could be used as a password. should i just get the inputs one by one and try to label them with names then use that to create a string? im working with the: Keypad Library for Arduino Author: Mark Stanley, Alexander Brevig
You simply get the characters one by one and add them to an array. Something like this
char password[5]; // one extra char to null terminate the string
memset (password, 5, 0); // clear the array
for (int i = 0; i < 4; i++)
password[i] = getKey();
I’m not familiar with the keypad library and I’ve assumed getKey() doesn’t return until a key is pressed. If getKey() returns a value indicating there was no key pressed the code would be more like this.
char password[5]; // one extra char to null terminate the string
memset (password, 5, 0); // clear the array
int k;
for (int i = 0; i < 4; i++) {
do {
k = getKey();
} while (k == -1);
password[i] = k;
}
Rob
I’m not familiar with the keypad library and I’ve assumed getKey() doesn’t return until a key is pressed.
Wrong. It returns the key currently being pressed, which can include no_key.
tanks. i think both of you will have helped by the time im down writing my code.