Skip to content

Instantly share code, notes, and snippets.

@teomaragakis
Last active Nov 25, 2015
Embed
What would you like to do?
HC-548 matrix keypad test code. Read the full blog post on www.teomaragakis.com/hardware/electronics/testing-the-hc-548-matrix-keypad/
/*
+-----+
+----[PWR]-------------------| USB |--+
| +-----+ |
| GND/RST2 [ ][ ] |
| MOSI2/SCK2 [ ][ ] A5/SCL[ ] | C5
| 5V/MISO2 [ ][ ] A4/SDA[ ] | C4
| AREF[ ] |
| GND[ ] |
| [ ]N/C SCK/13[ ] | B5
| [ ]v.ref MISO/12[ ] | .
| [ ]RST MOSI/11[ ]~| .
| [ ]3V3 +---+ 10[X]~| .
| [X]5v | A | 9[X]~| .
| [X]GND -| R |- 8[X] | B0
| [ ]GND -| D |- |
| [ ]Vin -| U |- 7[X] | D7
| -| I |- 6[X]~| .
| [ ]A0 -| N |- 5[X]~| .
| [ ]A1 -| O |- 4[X] | .
| [ ]A2 +---+ INT1/3[X]~| .
| [ ]A3 INT0/2[ ] | .
| [ ]A4/SDA RST SCK MISO TX>1[ ] | .
| [ ]A5/SCL [ ] [ ] [ ] RX<0[ ] | D0
| [ ] [ ] [ ] |
| UNO_R3 GND MOSI 5V ____________/
\_______________________/
http://busyducks.com/ascii-art-arduinos
*/
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {3, 4, 5, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 8, 9, 10}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
Serial.println("Starting keypad...");
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment