In this tutorial the assumption is that you have never used a keypad with your Arduino. Because of that I will make an attempt to cover everything you need to get it working.
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
#define ledPin 13
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these pins,
// eg. ROW0 = Arduino pin2.
byte rowPins[] = { 9, 8, 7, 6 };
// Connect keypad COL0, COL1 and COL2 to these pins,
// eg. COL0 = Arduino pin6.
byte colPins[] = { 12, 11, 10 };
//create a new Keypad
Keypad keypad = Keypad(rowPins, colPins, sizeof(rowPins), sizeof(colPins));
void setup()
{
digitalWrite(ledPin, HIGH);
Serial.begin(9600);
}
void loop()
{
char key = keypad.getKey();
if (key) { // same as if(key != NO_KEY)
Serial.println(key);
}
}