Hi, I tried to write code for 4x5 Matrix Keyboard.
There are many examples for 3x4 and 4x4 but not many for 4x5.
At last, I have a running code. And I wanted to share it.
Thanks for all sharings.
HW : Arduino Mega (clone)
4x5 keypad 4 Columns, 5 Rows {F1 F2 # * },{1 2 3 UP}, {4 5 6 DOWN}, {7 8 9 ESC}, {LEFT 0 RIGHT ENT}
References :
Cable Connections between MEGA and Keypad.
10 9 8 7 6 5 4 3 2 Arduino MEGA Pins
| | | | | | | | |
O O O O O O O O O Keypad -- 9 pins.
Face Upright position
Like
F1 F2 # *
1 2 3 UP , etc.
CODE :
// rdiot-s187/basic_test.ino at master · rdiot/rdiot-s187 · GitHub
// RDIoT Demo :: 4x5 Matrix Array 20 Keypad [S187]
#include <Wire.h>
#include <Keypad.h>
const byte numRows= 5; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad
//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]=
{
{'A','B','#','*'},
{'1','2','3','U'},
{'4','5','6','D'},
{'7','8','9','C'},
{'L','0','R','E'}
};
byte rowPins[numRows] = {2, 3, 4, 5, 6};
byte colPins[numCols]= {10, 9, 8, 7};
//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
String numstr = "";
void setup(){
Serial.begin(9600);
Serial.println("Setup");
} // setup
void loop()
{
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY) {
// Serial.print(keypressed);
//lcd.setCursor(0,1);
Serial.println("keypressed=" + (String)keypressed + " ");
switch (keypressed) {
case '1':
numstr = "1 ";
break;
case '2':
numstr = "2 ";
break;
case '3':
numstr = "3 ";
break;
case '4':
numstr = "4 ";
break;
case '5':
numstr = "5 ";
break;
case '6':
numstr = "6 ";
break;
case '7':
numstr = "7 ";
break;
case '8':
numstr = "9 ";
break;
case '0':
numstr = "0 ";
break;
case 'A':
numstr = "F1 ";
break;
case 'B':
numstr = "F2 ";
break;
case 'C':
numstr = "ESC ";
break;
case 'E':
numstr = "ENTER";
break;
case 'D':
numstr = "DOWN ";
break;
case 'U':
numstr = "UP ";
break;
case 'R':
numstr = "RIGHT ";
break;
case 'L':
numstr = "LEFT ";
break;
case '':
numstr = " ";
break;
case '#':
numstr = "# ";
break;
default:
break;
}
if(numstr !="") {
//lcd.setCursor(0,2);
Serial.println("numstr=" + (String)numstr + " ");
}
}
} // loop
sample.pdf (48.5 KB)