http://playground.arduino.cc/code/Keypad
You won't need external resistors or diodes because the library uses the internal pullup resistors and additonally ensures that all unused column pins are high-impedance.
#include <Keypad.h>
const byte ROWS = 2; //four rows
const byte COLS = 2; //three columns
char keys[ROWS][COLS] = {
{'B','1'},
{'I','2'},
};
byte rowPins[ROWS] = {5, 4,}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7,}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
if (key != NO_KEY){
Serial.println(key);
}
}
For 5x2:
const byte ROWS = 5; //four rows
const byte COLS = 2; //three columns
char keys[ROWS][COLS] = {
{'B','1'},
{'I','2'},
{'N','3'},
{'G','4'},
{'O','5'},
};
And add pins accordingly.
