243
Chapter 22 Matrix Keypad
In the "while" cycle, use the function key= keypad.
getKey
() to read the keyboard constantly. If there is a key
pressed, its key code will be stored in the variable "key", then be printed out.
w h ile
(
1
){
key
=
keypad
.
getKey
();
//get the state of keys
i f
(
key
) {
// if a key is pressed, print out its key code
printf
(
"You Pressed key : %c \n"
,
key
);
}
}
The library Keypad used for RPi is transplanted from the Arduino library Keypad. And the source files can be
obtained by visiting
http://playground.arduino.cc/Code/Keypad
. As for transplanted function library, the
function and method of all classes, functions, variables, etc. are the same as the original library. Partial contents
of the Keypad library are described below:
c l ass K eypad
K e ypad
(
char
*
userKeymap
,
b yte
*
row
,
b yte
*
col
,
b yte n umRows
,
b yte n umCols
);
Constructor, the parameters are: key code of keyboard, row pin, column pin, the number of rows, the
number of columns.
c h ar
g etKey
();
Get the key code of the pressed key. If no key is pressed, the return value is NULL.
v o id
s etDebounceTime
(
uint
);
Set the debounce time. And the default time is 10ms.
v o id
s etHoldTime
(
uint
);
Set the time when the key holds stable state after pressed.
b o ol
i sPressed
(
char
k eyChar
);
Judge wether the key with code "keyChar" is pressed.
c h ar
w aitForKey
();
Wait for a key to be pressed, and return key code of the pressed key.
K e yState g etState
();
Get state of the keys.
b o ol
k eyStateChanged
();
Judge whether there is a change of key state, then return True or False.
For More information about Keypad, please visit:
http://playground.arduino.cc/Code/Keypad
or through the
opening file "Keypad.hpp".
Summary of Contents for Ultimate Starter Kit
Page 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Page 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Page 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Page 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Page 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Page 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...