Reason for being

This example was chosen to demonstrate keypad pin assignment, setup and use.


Example

/* @file SerialKeypad.pde
 || @version 1.0
 || @author Alexander Brevig
 || @contact alexanderbrevig@gmail.com
 ||
 || @description
 || | Another simple test program for the matrix keypad driver.
 || #
 */
#include <Keypad.h>

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these pins, 
// eg. ROW0 = Arduino pin2.
byte rowPins[] = { 9, 8, 7, 6 };

// Connect keypad COL0, COL1, COL2 and COL3 to these pins, 
// eg. COL0 = Arduino pin6.
byte colPins[] = { 12, 11, 10 };

//create a new Keypad
Keypad kpd = Keypad(rowPins, colPins, sizeof(rowPins), sizeof(colPins));

#define ledPin 13	//LED connected to digital pin 13

void setup()
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  Serial.begin(9600);
}

void loop()
{
  char key = kpd.getKey();

  if (key)    // same as if(key != NO_KEY)
    Serial.print(key);
  if (key == '*')
    digitalWrite(ledPin, HIGH);   // sets the LED on
  if (key == '#')
    digitalWrite(ledPin, LOW);    // sets the LED off
}

Share