FYI - I have been able to modify the keypad library to return a String. This can then be converted into a number and used for calculations.
The code below has existing lines in it so you can see where to add. Test, let me know if you have any improvements.
Working Sketch:
#include <Keypad.h>
//By Robert Wagner 4-23-2012
//keypad - ACT Components 07-30008-000
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = { {'1','2','3','^'}, {'4','5','6','V'}, {'7','8','9','R'}, {'<','0','>','E'}};
byte rowPins[ROWS] = {4, 5, 6, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {11, 10, 9, 8}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//end keypad
void setup()
{
Serial.begin(9600); //Serial LCD, Parallax 27979. Hooked to pin 1 4x20
Serial.write(17); //command flag for backlight stuff - turn on backlight
delay(10);
}
void loop()
{
delay(100);
Serial.write(128); //goto position 0,0 on LCD
Serial.print("Enter A String");
String test = keypad.getString(5,'E'); //request string from keypad, 5 characters long, escape when E is pressed
//Note: test will return after 5 characters are pressed or the Escape character is pressed
Serial.write(12); //clear LCD
Serial.write(148); //goto position 1,0 on LCD
Serial.print("You entered: ");
Serial.print(test);
char test12[10]; //create empty character array to copy string into
memset(test12, 0, sizeof(test12)); //clear buffer
test.toCharArray(test12, sizeof(test12), 0); //copy string into character array
Serial.write(168); //goto position 2,0 on LCD
Serial.print("As a number: ");
Serial.print(test12);
Serial.write(188); //goto position 3,0 on LCD
unsigned long test13=atol(test12); //convert character array into unsigned long for math
Serial.print("Number *2: ");
Serial.print(test13*2);
}
This required a change to keypad.h
.....
char getKey();
String getString(int Length, char EscapeChar); //added this line 4-20-2012 RW
KeyState getState();
.....
and additions to keypad.cpp
....
char Keypad::getKey() {
// Return the new key value if a keypress was detected. By testing for
// keyStateChanged() we don't return a keypress more than once.
if( getKeyState()==PRESSED && keyStateChanged() )
return currentKey;
return NO_KEY; // Otherwise just return the default key value:
}
String Keypad::getString(int Length, char EscapeChar) { //added this line 4-20-2012 RW
String currentString=""; //added this line 4-20-2012 RW
int count = 0; //added this line 4-20-2012 RW
while (getKey() != EscapeChar){ //added this line 4-20-2012 RW
delay(100); //added this line 4-20-2012 RW
if( getKeyState()==PRESSED && keyStateChanged() ) //added this line 4-20-2012 RW
if( currentKey != NO_KEY){ //added this line 4-20-2012 RW
if (currentKey != EscapeChar){ //added this line 4-20-2012 RW
currentString += currentKey; //added this line 4-20-2012 RW
count ++; //added this line 4-20-2012 RW
if (count == Length){ //added this line 4-20-2012 RW
return currentString; //added this line 4-20-2012 RW
} //added this line 4-20-2012 RW
} //added this line 4-20-2012 RW
else { //added this line 4-20-2012 RW
return currentString; //added this line 4-20-2012 RW
} //added this line 4-20-2012 RW
} //added this line 4-20-2012 RW
} //added this line 4-20-2012 RW
} //added this line 4-20-2012 RW
char Keypad::waitForKey() {
char waitKey = NO_KEY;
....