# Data Returned from keypad

**URL:** <https://forum.arduino.cc/t/data-returned-from-keypad/680934>\
**Category:** Programming\
**Created:** [November 1, 2020, 9:47pm UTC](https://forum.arduino.cc/t/data-returned-from-keypad/680934 "2020-11-01T21:47:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steveiboy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/steveiboy/32/1098630_2.png) [@Steveiboy](https://forum.arduino.cc/u/Steveiboy)\
**Post date:** [November 1, 2020, 9:47pm UTC](https://forum.arduino.cc/t/data-returned-from-keypad/680934/1 "2020-11-01T21:47:55Z")

</div>

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

```cpp
#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

```cpp
//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

```cpp
//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

---

<div class="post-metadata">

**Author:** ![Blackfin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/blackfin/32/238871_2.png) [@Blackfin](https://forum.arduino.cc/u/Blackfin)\
**Post date:** [November 1, 2020, 10:27pm UTC](https://forum.arduino.cc/t/data-returned-from-keypad/680934/2 "2020-11-01T22:27:42Z")

</div>

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:

```cpp
value = 10 + keyboard_value - 'A'

```

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [November 1, 2020, 10:28pm UTC](https://forum.arduino.cc/t/data-returned-from-keypad/680934/3 "2020-11-01T22:28:04Z")

</div>

'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.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [November 1, 2020, 10:44pm UTC](https://forum.arduino.cc/t/data-returned-from-keypad/680934/4 "2020-11-01T22:44:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Erik\_Baas](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/erik_baas/32/1098646_2.png) [@Erik\_Baas](https://forum.arduino.cc/u/Erik_Baas)\
**Post date:** [November 1, 2020, 10:52pm UTC](https://forum.arduino.cc/t/data-returned-from-keypad/680934/5 "2020-11-01T22:52:27Z")

</div>

```arduino
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. 😉

---

<div class="post-metadata">

**Author:** ![Steveiboy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/steveiboy/32/1098630_2.png) [@Steveiboy](https://forum.arduino.cc/u/Steveiboy)\
**Post date:** [November 1, 2020, 11:27pm UTC](https://forum.arduino.cc/t/data-returned-from-keypad/680934/6 "2020-11-01T23:27:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [November 2, 2020, 3:42pm UTC](https://forum.arduino.cc/t/data-returned-from-keypad/680934/7 "2020-11-02T15:42:59Z")

</div>

> 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).

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:49am UTC](https://forum.arduino.cc/t/data-returned-from-keypad/680934/8 "2021-05-06T00:49:47Z")

</div>

Closed on May 6, 2021, 12:49am UTC


