examples(mcp23009e): Add practical usage examples. #74#187
Conversation
There was a problem hiding this comment.
Pull request overview
Adds four interactive MCP23009E example sketches demonstrating D-PAD input with LEDs, buzzer, timing, and Morse decoding.
Changes:
- Adds Simon-style memory game using D-PAD input and onboard LEDs.
- Adds reaction timer and melody player examples driven by D-PAD buttons.
- Adds Morse code input/decoder example.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 11 comments.
| File | Description |
|---|---|
lib/mcp23009e/examples/SimonGame/SimonGame.cpp |
Adds Simon-style sequence memory game. |
lib/mcp23009e/examples/ReactionTimer/ReactionTimer.cpp |
Adds LED-based reaction timer using the UP button. |
lib/mcp23009e/examples/MusicPlayer/MusicPlayer.cpp |
Adds D-PAD-triggered buzzer melodies. |
lib/mcp23009e/examples/MorseCode/MorseCode.cpp |
Adds Morse code input and serial decoding example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,140 @@ | |||
| // SPDX-License-Identifier: GPL-3.0-or-later | |||
There was a problem hiding this comment.
fix in commit : fc0433e
Rename example files to snake_case.
| @@ -0,0 +1,43 @@ | |||
| // SPDX-License-Identifier: GPL-3.0-or-later | |||
There was a problem hiding this comment.
fix in commit : fc0433e
Rename example files to snake_case.
| @@ -0,0 +1,115 @@ | |||
| // SPDX-License-Identifier: GPL-3.0-or-later | |||
There was a problem hiding this comment.
fix in commit : fc0433e
Rename example files to snake_case.
| @@ -0,0 +1,90 @@ | |||
| // SPDX-License-Identifier: GPL-3.0-or-later | |||
There was a problem hiding this comment.
fix in commit : fc0433e
Rename example files to snake_case.
| for (const auto& [pinNumber, melody] : kMelodies) { | ||
| if (expander.getLevel(pinNumber) == MCP23009_LOGIC_LOW) { | ||
| melody(); |
There was a problem hiding this comment.
fix in commit : 5fe8808
Configure each D-PAD pin as input with pull-up before polling — begin() resets the expander and disables pull-ups by default.
| pinMode(LED_GREEN, OUTPUT); | ||
| pinMode(LED_BLUE, OUTPUT); | ||
|
|
||
| Serial.println("DpadReader — press a D-PAD button."); |
There was a problem hiding this comment.
fix in commit : ee26a74
Updated startup message to describe the Simone-game mappings instead of the generic DpadReader label.
| internalI2C.begin(); | ||
| expander.begin(); | ||
|
|
||
| Serial.println("DpadReader — press a D-PAD button."); |
There was a problem hiding this comment.
fix in commit : 5fe8808
Updated startup message to describe the button-to-melody mappings instead of the generic DpadReader label.
| internalI2C.begin(); | ||
| expander.begin(); | ||
|
|
||
| Serial.println("DpadReader — press a D-PAD button."); |
There was a problem hiding this comment.
fix in commit : 85eabb6
Updated startup message to describe the Simone-game mappings instead of the generic DpadReader label.
| delay(random(300, 1500)); | ||
| digitalWrite(LED_RED, HIGH); | ||
| uint32_t startTime = millis(); | ||
| while (true) { | ||
| if (expander.getLevel(MCP23009_BTN_UP) == MCP23009_LOGIC_LOW) { |
There was a problem hiding this comment.
fix in commit : af0963a
Wait for the button to be released before starting so a held press can't trigger an instant reaction time.
| } | ||
|
|
||
| internalI2C.begin(); | ||
| expander.begin(); |
There was a problem hiding this comment.
fix in commit : af0963a
Any press during the random delay window is ignored — the timer only starts after the LED lights up.
Summary
Add four interactive example sketches for the MCP23009E driver.
close #74
Changes
Add
SimonSays— memory game using the D-PAD and on-board LEDs.The board shows a growing sequence of directions via coloured LEDs;
the player must replay it on the D-PAD. Score is printed to the
serial monitor.
Add
ReactionTime— reaction-time trainer. The red LED lights upafter a random delay (300–1500 ms); the player presses the UP button
as fast as possible and the elapsed time is printed to the serial
monitor.
Add
MelodyPlayer— plays a different 8-bit melody on the on-boardbuzzer depending on which D-PAD button is pressed: UP → Tetris,
DOWN → Mario, LEFT → Zelda, RIGHT → Pokémon.
Add
MorseDecoder— Morse code input via a single button. A shortpress (< 300 ms) inputs a dot, a long press inputs a dash. After
1 second of inactivity the accumulated code is decoded and the
matching letter is printed to the serial monitor.
Checklist
make lintpasses (clang-format)make buildpasses (PlatformIO)make test-nativepasses (if native tests exist)make test-hardwarepasses on a connected STeaMi (if hardware tests exist)