Skip to content

Commit c80e36a

Browse files
authored
Create README.adoc file (#4)
* Change wiring to make it easier * Include first version of README.adoc * Fix image syntax * Fix number of columns in table * Remove 'Installation' section * Put terminal output as a note * Remove NOTE * Use plain text Code Block instead * Fix URLs to LICENSE and CONTRIBUTING * Another attempt of fixing contributing and licensing * Put links in line
1 parent 4a0634d commit c80e36a

File tree

3 files changed

+128
-8
lines changed

3 files changed

+128
-8
lines changed

gpio/keypad/README.adoc

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
= Keypad Example for Raspberry Pi Pico
2+
3+
This document provides details about the 4x4 keypad example included in the larger repository of examples for Raspberry Pi Pico. This example demonstrates how to interface a 4x4 matrix keypad with the Pico and includes both simple and enhanced key detection modes.
4+
5+
== Introduction
6+
7+
This example shows how to use a 4x4 matrix keypad with the Raspberry Pi Pico. It has been enhanced to support detecting multiple key presses simultaneously, alongside the original single key press functionality.
8+
9+
== Features
10+
11+
* Simple key detection (one key press at a time)
12+
* Enhanced key detection (multiple keys pressed simultaneously)
13+
* Configurable maximum number of simultaneous key presses
14+
* Mode switching via macro definition
15+
16+
== Hardware Requirements
17+
18+
* Raspberry Pi Pico
19+
* 4x4 matrix keypad
20+
* Connecting wires
21+
22+
== Wiring Instructions
23+
24+
Follow these wiring instructions to connect the 4x4 matrix keypad to the Raspberry Pi Pico:
25+
26+
[image2]
27+
image::pico_keypad_connection.png[Keypad Connection Diagram]
28+
29+
=== Wiring Table
30+
31+
The following table shows the GPIO pins used for the rows and columns of the keypad:
32+
33+
[width="50%",cols="1,1,1",options="header"]
34+
|===
35+
| Keypad Row/Column | GPIO Pin | Pin Number
36+
37+
| Row 0 | GP9 | 9
38+
| Row 1 | GP8 | 8
39+
| Row 2 | GP7 | 7
40+
| Row 3 | GP6 | 6
41+
42+
| Column 0 | GP5 | 5
43+
| Column 1 | GP4 | 4
44+
| Column 2 | GP2 | 2
45+
| Column 3 | GP1 | 1
46+
|===
47+
48+
Ensure that the keypad rows and columns are connected to the GPIO pins on the Pico as indicated in the table.
49+
50+
== Usage
51+
52+
This example can be compiled and run to interact with the keypad.
53+
54+
=== Simple Mode
55+
56+
In simple mode, the `get_keypad_value` function returns a single character corresponding to the pressed key. If no key is pressed, it returns a constant value indicating no key press.
57+
58+
[source,c]
59+
----
60+
char get_keypad_value();
61+
----
62+
63+
=== Enhanced Mode
64+
65+
In enhanced mode, the `get_keypad_result` function returns a `KeypadResult` structure containing the count of pressed keys and a list of those keys.
66+
67+
[source,c]
68+
----
69+
KeypadResult get_keypad_result();
70+
----
71+
72+
The `KeypadResult` structure is defined as follows:
73+
74+
[source,c]
75+
----
76+
typedef struct {
77+
int count; // Number of pressed keys
78+
char keys[MAX_MULTI_KEYS]; // Pressed keys
79+
} KeypadResult;
80+
----
81+
82+
== Example Output
83+
84+
=== Simple Mode
85+
86+
If a key is pressed, the output will be:
87+
88+
[source, plain]
89+
----
90+
Key 'A' pressed
91+
----
92+
93+
If no key is pressed, the output will be:
94+
95+
[source, plain]
96+
----
97+
No key pressed
98+
----
99+
100+
=== Enhanced Mode
101+
102+
If multiple keys are pressed, the output will be:
103+
104+
[source, plain]
105+
----
106+
Bang!!! '2' key(s) are pressed. Keys: A, B
107+
----
108+
109+
If no keys are pressed, the output will be:
110+
111+
[source, plain]
112+
----
113+
No key pressed
114+
----
115+
116+
== Additional Information
117+
118+
For contributing to the repository, refer to the link:../../CONTRIBUTING.md[CONTRIBUTING.md] file.
119+
120+
For licensing information, see the link:../../LICENSE.TXT[LICENSE.TXT] file.

gpio/keypad/keypad.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ typedef struct {
3838

3939

4040
const uint8_t keypad_rows_pins[KEYPAD_NUM_ROWS] = {
41-
10,
42-
11,
43-
12,
44-
13,
41+
9, // GP9
42+
8, // GP8
43+
7, // GP7
44+
6, // GP6
4545
};
4646

4747

4848
const uint8_t keypad_columns_pins[KEYPAD_NUM_COLUMNS] = {
49-
18, // GP18
50-
19, // GP19
51-
20, // GP20
52-
21, // GP21
49+
5, // GP5
50+
4, // GP4
51+
3, // GP2
52+
2, // GP1
5353
};
5454

5555

78.1 KB
Loading

0 commit comments

Comments
 (0)