/* @file CustomKeypad.pde || @version 1.0 || @author Alexander Brevig || @contact alexanderbrevig@gmail.com || || @description || | Demonstrates changing the keypad size and key values. || # */ /* * Kaypad_Basic.ino * modified by c.d.odom on June 21, 2020 * * A basic 4x4 matrix-style keypad app for Arduino. * It utilizes the Keypad.h library, you must first load the library. * Here's how: * 1. Find the Keypad.zip file, which contains the library files. (If you don't have it, you can * download it from my textbook's site at https://www.pcrduino.com/downloads/ * under Sample Code Downloads >> Extras.) * * 2. Then from the menu: Sketch >> Include Library >> Add .ZIP Library... >> (then locate and select the Keypad.zip folder) * * 3. Connect the 8 wires of the keypad to 8 pins on the Arduino. * Pinout: Hold the keypad so the connecting wires hang down. (With the Lafvin module the letters on the keypad are upright in this orientation.) * The right-most wire should be connected to Arduino pin 2. The left-most wire connect to Arduino pin 9. * * 4. Run the code, open the Serial Monitor, and press the buttons. The key press should echo on the Serial Monitor. * * KEYPAD PINOUT * ________________ * | | * | 1 2 3 A | * | 4 5 6 B | * | 7 8 9 C | * | * 0 # D | * | | * ---------------- * | | | | | | | | * | | | | | | | | * | | | | | | | | * | | | | | | | | * | | | | | | | | * | | | | | | | | * ^ ^ ^ ^ ^ ^ ^ ^ * 9 8 7 6 5 4 3 2 <<< Arduino pin numbers */ #include const byte ROWS = 4; //four rows const byte COLS = 4; //four columns //define the cymbols 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] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad byte colPins[COLS] = {5, 4, 3, 2}; //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); } void loop(){ char customKey = customKeypad.getKey(); if (customKey){ Serial.println(customKey); } }