skip navigational linksPJRC
Shopping Cart Checkout Shipping Cost Download Website
Home MP3 Player 8051 Tools All Projects PJRC Store Site Map
You are here: Teensy Teensyduino Libraries Keypad

PJRC Store
Teensy 3.1, $19.80
Teensy 2.0, $16.00
Teensy++ 2.0, $24.00
USB Cable, $4.00
Teensy
Main Page
Teensy 3.1
Getting Started
How-To Tips
Code Library
Projects
Teensyduino
Reference

Keypad Library

Keypad, written by Mark Stanley and Alexander Brevig, allows you to connect a Keypad with row-column matrix wiring.

Download: Keypad.zip (version 3.1)

Hardware Requirements


The keypad's signals may connect to any digital pins, but avoid using the one with a LED attached.

Example Use

This example can be opened from the menu: File > Examples > Keypad > HelloKeypad

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //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);
  }
}
In this screenshot, each key was pressed once.


Each key pressed once.

More Hardware Pictures


Bottom side wiring, 7 signals between keypad and Teensy

Multiple Keys & Key Events

The getKey() function is simple and easy to use, but it can only report a single key.

Keypad can detect multiple keys pressed simultaneously. Keypad can also report events, when each key is pressed, held, released, and idle after being released. An example for this more advanced usage can be opened from the menu: File > Examples > Keypad > MultiKey.

Links

Arduino Playground Page has more details to use Keypad.