Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
๐ Ready to explore and create with us? Click [here] and join today!
2.19 Keypad๏
Overview๏
In this lesson, you will learn to use Keypad. Keypad can be applied into various kinds of devices, including mobile phone, fax machine, microwave oven and so on. It is commonly used in user input.
Components Required๏

Fritzing Circuit๏
In this example, we extend the pins 1~8 of Keypad to connect to the digital pins 2~9.

Schematic Diagram๏

Code๏
Note
You can open the file
2.19_keypad.ino
under the path ofsunfounder_vincent_kit_for_arduino\code\2.19_keypad
directly.The
Keypad
library is used here, you can install it from the Library Manager.
After uploading the codes to the Mega2560 board, on the serial monitor, you can see the value of the key currently pressed on the Keypad.
Code Analysis๏
By calling the Keypad.h library, you can easily use Keypad.
#include <Keypad.h>
Library Functions๏ผ
Keypad(char *userKeymap, byte *row, byte *col, byte numRows, byte numCols)
Initializes the internal keymap to be equal to userKeymap.
userKeymap
: The symbols on the buttons of the keypads.row, col
: Pin configuration.numRows, numCols
: Keypad sizes.
char getKey()
Returns the key that is pressed, if any. This function is non-blocking.
Phenomenon Picture๏
