EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #241 background imageLoading...
Page #241 background image
241
Chapter 22 Matrix Keypad
www.freenove.com
support@freenove.com
Code
This code is used to obtain all key code of 4x4 Matrix Keypad, when one of keys is pressed, the key code will
be printed out in the terminal window.
C Code 22.1.1 MatrixKeypad
First observe the project result, and then analyze the code.
1. Use cd command to enter 22.1.1_MatrixKeypad directory of C code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/C_Code/22.1.1_MatrixKeypad
2. Code of this project contains a custom header file. Use the following command to compile the code
MatrixKeypad.cpp, Keypad.cpp and Key.cpp generate executable file MatrixKeypad. And the custom
header file will be compiled at the same time.
gcc MatrixKeypad.cpp Keypad.cpp Key.cpp -o MatrixKeypad -lwiringPi
3. Run the generated file "MatrixKeypad".
sudo ./MatrixKeypad
After the program is executed, press any key on the MatrixKeypad, the terminal will print out the
corresponding key code. As is shown below:
The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Keypad.hpp"
#include <stdio.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = { //key code
{ '1', '2','3','A'},
{ '4', '5','6','B'},
{ '7', '8','9','C'},
{ '*', '0','#','D'}
};
byte rowPins[ ROWS] = {1, 4, 5, 6 }; //connect to the row pinouts of the keypad
byte colPins[ COLS] = {12,3, 2, 0 }; //connect to the column pinouts of the keypad
//create Keypad object

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish