|
| 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. |
0 commit comments