6v6gt:
If you have got any code already where you are reading form the keypad, then post it. There may be a nicer solution.
I have been mucking around with stuff buts its absolute rubbish and it doesnt work, ill post something now.
*
*/
#include <Keypad.h>
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 45, 47, 49, 51 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 39, 41, 43};
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define ledpin 13
void setup()
{
pinMode(ledpin,OUTPUT);
digitalWrite(ledpin, HIGH);
Serial.begin(9600);
}
int i=0;
char Key;
char entryStr[3];
void loop(){
char key = kpd.getKey();
if (key){
if (key == '*'){
memset(entryStr, 0, sizeof(entryStr));
i=0;
key=0;
Serial.println("");
Serial.println("Canceled");
} else if (key != '#'){
entryStr[i]= key;
i++;
Serial.print(key);
}
else {
Serial.println("");
i=0;
key=0;
Serial.println(entryStr);
}
}
switch(entryStr)
{
case '10':
Serial.print("ENTRY 10");
Serial.println();
break;
case 12:
Serial.print("Entry 12");
Serial.println();
break;
default:
Serial.print("NOTHING");
Serial.println();
}
}
}
the problem with this code is that entryStr wont pass through the switch statement because it is not a integer.
odometer:
Do not confuse the characters '1', '2', etc., with the numeric values 1, 2, etc.
This is how it works:
char c = '1'; // c is '1' (a character)
int x = c; // x is 49 (a number)
int y = (c - '0'); // y is 1 (a number)
char t = '2'; // t is '2' (a character)
char u = '5'; // u is '5' (a character)
int v = ((t - '0') * 10) + (u - '0'); // v is 25 (a number)
i get you, so what are you trying to say? that if i work out whether im using a character or a number im able to 'concatenate' so to speak.. because through the keypad.h library when i return the keypad number 1, it returns 1 as a char, however if i store it as a integer it returns 49, which is ASCII im assuming?