Data Returned from keypad

I'm using a standard 3x4 keypad and am able to get the show which key has been entered with the code below.

#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 3;
char KeypadData;
//used for 4x4 keypad
// Array to represent keys on keypad
/*
  char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
  };
  // Connections to Arduino
  byte rowPins[ROWS] = {9, 8, 7, 6};
  byte colPins[COLS] = {5, 4, 3, 2};
*/
//used for 3x4 krypad
// Array to represent keys on keypad
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
// Connections to Arduino
//byte rowPins[ROWS] = {9, 8, 7, 6};
// Connections to Arduino
byte rowPins[ROWS] = {43, 41, 39, 37}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {31, 33, 35}; //connect to the column pinouts of the keypad
// Create keypad object
Keypad customKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
  // Setup serial monitor
  Serial.begin(115200);

  Serial.println("Initialize the Keypad");// Initialize the LCD.
}

void loop() {

  KeypadData = customKeypad.getKey();
  if (KeypadData) {
    Serial.println(KeypadData);

  }
}

What I would like is to have the keys numbered 1 through to 12, So if I press the *, 0 , # keys I would like them to display 10, 11, 12 instead.

I've tried to change these variables to a int or byte char keys and char KeypadData but do not get the correct number back.

This is what I've also changed from

//used for 3x4 krypad
// Array to represent keys on keypad
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

to

//used for 3x4 krypad
// Array to represent keys on keypad
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'10', '11', '12'}
};

But does not work is there away that I can do it ?

Thanks

The single quotes in '10' are intended to encapsulate a single byte/character. '10' is two characters.

Perhaps you can have them map instead to 'A', 'B' and 'C' and, in your code, check if the returned value is > '9' and if so, perform:

value = 10 + keyboard_value - 'A'

'12' is not a character constant that can fit in a single char variable. (it will fit in an int variable).

'C' is the hex equivalent of 1210 - maybe you could explore this approach.

Is there any reason why the entries in the keys array cannot simply be numbers rather than characters ?

char keys[ROWS][COLS] = {
  {49, 50, 51},
  {52, 53, 54},
  {55, 56, 57},
  {58, 59, 60}
};

...

void loop() {
KeypadData = customKeypad.getKey();
  if (KeypadData) {
    Serial.println(KeypadData - 48);
  }
}

Edit:

UKHeliBob:
Is there any reason why the entries in the keys array cannot simply be numbers rather than characters ?

That's what I thought. :wink:

Thanks guys that's give me some foo for thought. Also I may need to expand it to 16 keys.

I was trying to make change as I've got some old code that I used many years ago which used and I2C keypad (BV4506 module from ByVAC )which you can not get anymore and my keypad is now broken.
If I remember correctly these just returned an INT value and it returned a 255 if no key was pressed, and when you pressed *, 0 , # key it returned the value of 10, 11, 12.

I will have a play around if not will have to go through all the code and change it to suit new keypad

UKHeliBob:
Is there any reason why the entries in the keys array cannot simply be numbers rather than characters ?

You can use any 8-bit value except zero (reserved for NO_KEY).