Introduction: How to Turn Your 4X4 Keypad Into 4X4XN

I was looking for a keypad with 26+ keys to represent the English alphabet but not only I couldn't find any but also the idea of having two keypads seemed inconvenient and too much work, so I needed to find a way to turn my 4X4 keypad into at least a 4X4X2 which later as I found out could be easily be turned into 4X4XN ie you can have each key of your keypad represent as many different characters given that they are somewhat mathematically related.

in this instructable I will show you have to make a 4X4X3 where each key represents three consecutive letters.

Step 1: Lets Get Our Components

1- a Keypad , we will be using a 4X4 but any size could do

2- 8 male - male jumper Wires

and that's all, aside from your arduino of course :)

Step 2: Lets Connect Our Circut

1- connect one end of your wires to the Keypad

2- connect the other end to arduino in same order in which they are connected to keypad, I choose from pin 5-12

Step 3: Lets Code

the main logic behind the code is to make use of a predefined function within the Keypad library, which is the getState(). through which we can tell:

1 - when a key is press to save Value

2- if and when and for how long a key is held, such that :

a- no hold = original character

b- short hold = original character +1

c- long hold = original character +2

3-when a key is released , where we will be adding our hold variable to mapped character and print;

#include

const byte rows = 4;
const byte columns = 4;

int holdDelay = 500; //how long each hold will last int n = 3; // how many letters we want each key to represent int state = 0; //used to indicate if hold occured and for how long, state =0 no hold ,state =1 short hold , state = 2 long hold char key = 0;

//we will definne the key map as on the key pad: * notice each letter is spaced by 3 which our n char keys[rows][columns] = { {'a', 'd', 'g', 'j'}, {'m', 'p', 's', 'v'}, {'y', '1', '4', '7'}, {'-', '-', '#', '-'} };

byte rowPins[rows] = {5, 6, 7, 8}; byte columnPins[columns] = {9, 10, 11, 12};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, columnPins, rows, columns); void setup() { // put your setup code here, to run once: Serial.begin(9600);

}

void loop() { // put your main code here, to run repeatedly: char temp = keypad.getKey();

if ((int)keypad.getState() == PRESSED) {

if (temp != 0) { key = temp; } } if ((int)keypad.getState() == HOLD) { state++; state = constrain(state, 1, n-1); delay(holdDelay); }

if ((int)keypad.getState() == RELEASED) {

key += state; state = 0; Serial.println(key);

}

delay(100); }


Comments

About This Instructable

479views

9favorites

License:

Bio: Hi eveyone, my name is Raed, I'm a computer science student from Jordan, I'm passionate about learning and developing mobile games in Unity3D ... More »
More by RaedT:A Morse Code Translator( Light -> Text & Text ->Light)  How to turn your 4X4 keypad into 4X4XN Make a Punching Bag in Arduino and Unity Using a Joystic and Balloon
Add instructable to: