Skip to content

examples(mcp23009e): Add practical usage examples. #74#187

Open
DumontALINE wants to merge 9 commits into
mainfrom
feat/mcp23009e-example
Open

examples(mcp23009e): Add practical usage examples. #74#187
DumontALINE wants to merge 9 commits into
mainfrom
feat/mcp23009e-example

Conversation

@DumontALINE
Copy link
Copy Markdown
Contributor

@DumontALINE DumontALINE commented May 28, 2026

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 up
    after 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-board
    buzzer 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 short
    press (< 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 lint passes (clang-format)
  • make build passes (PlatformIO)
  • make test-native passes (if native tests exist)
  • make test-hardware passes on a connected STeaMi (if hardware tests exist)
  • README updated (if adding/changing public API)
  • Examples added/updated (if applicable)
  • Commit messages follow conventional commits format

Copilot AI review requested due to automatic review settings May 28, 2026 07:22
@github-actions github-actions Bot added this to the Phase 3 — Drivers simples milestone May 28, 2026
@DumontALINE DumontALINE requested a review from nedseb May 28, 2026 07:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : fc0433e
Rename example files to snake_case.

@@ -0,0 +1,43 @@
// SPDX-License-Identifier: GPL-3.0-or-later
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : fc0433e
Rename example files to snake_case.

@@ -0,0 +1,115 @@
// SPDX-License-Identifier: GPL-3.0-or-later
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : fc0433e
Rename example files to snake_case.

@@ -0,0 +1,90 @@
// SPDX-License-Identifier: GPL-3.0-or-later
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : fc0433e
Rename example files to snake_case.

Comment on lines +108 to +110
for (const auto& [pinNumber, melody] : kMelodies) {
if (expander.getLevel(pinNumber) == MCP23009_LOGIC_LOW) {
melody();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.");
Copy link
Copy Markdown
Contributor Author

@DumontALINE DumontALINE May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.");
Copy link
Copy Markdown
Contributor Author

@DumontALINE DumontALINE May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : 85eabb6
Updated startup message to describe the Simone-game mappings instead of the generic DpadReader label.

Comment on lines +31 to +35
delay(random(300, 1500));
digitalWrite(LED_RED, HIGH);
uint32_t startTime = millis();
while (true) {
if (expander.getLevel(MCP23009_BTN_UP) == MCP23009_LOGIC_LOW) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix in commit : af0963a
Any press during the random delay window is ignored — the timer only starts after the LED lights up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

examples(mcp23009e): Add practical usage examples.

3 participants