PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Devices
Interface
Keypad 4x4 Read Keys.c
1
/*
2
Keypad 4x4 Read Keys.c
3
Demonstrates how to read individual key presses with the keypad library.
4
*/
5
6
#include "
simpletools.h
"
// Libraries simpletools & keypad
7
#include "
keypad.h
"
8
9
int
rows[4] = {7, 6, 5, 4};
// Row I/O pins (top to bottom)
10
int
cols[4] = {3, 2, 1, 0};
// Column I/O pins (left to right)
11
12
int
values[16] = { 1, 2, 3,
'A'
,
// Values for each key in the 4x4
13
4, 5, 6,
'B'
,
14
7, 8, 9,
'C'
,
15
'*'
, 0,
'#'
,
'D'
};
16
17
int
main
()
// Main function
18
{
19
keypad_setup
(4, 4, rows, cols, values);
// Setup dimensions, keypad arrays
20
21
while
(1)
// Main loop
22
{
23
int
key =
keypad_read
();
// Get pressed key (or -1 for none)
24
25
if
(key <= 9)
// Display key value
26
print
(
"key = %d\r"
, key);
// If <= 9, dispaly as decimal
27
else
28
print
(
"key = %c\r"
, key);
// Otherwise, display as character
29
pause
(500);
// Wait 0.5 s before repeat
30
}
31
}
keypad_setup
void keypad_setup(int rowCount, int columnCount, int *rowPinCons, int *columnPinCons, int *buttonValues)
Set up the row and column dimensions, pins, and key values.
Definition:
keypad.c:24
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
keypad_read
int keypad_read(void)
Returns the first key pressed, or -1 if no key is pressed.
Definition:
keypad.c:42
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
keypad.h
Scans matrix keypad and returns a unique value for each key that is pressed. For an example circuit a...
main
int main(void)
Definition:
GraphicsTest.c:20
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17