Back to engineering archive

Record 084 / Firmware and control

ESP32 BLE game controller interface

An ESP32 BLE interface translating physical input into game controller actions, with timed button press and release handling.

Firmware development
ESP32BLEEncoder inputButton timing

Firmware flow

How a short gamepad button press is tracked

Two separate press and release helpers.

When the press helper is called

When the release helper is called

ActionRelease helper calledThis is a separate function call, not an automatic next instruction.
Result · YesRelease the button and clear its flag
Result · NoLeave the current state unchanged

The press helper sends one button press and records its start time when the button is not already held. A separately called release helper releases it once the configured hold time has elapsed.

The caller decides when each helper runs. This overview does not imply a blocking wait or prove the complete input mapping.

Read the implementation

press/release functions · selected source lines 94–107. Source inspection is not a hardware test.

void tapButtonIfNeeded(int btn, bool &pressedFlag, uint32_t &startedFlag) {
  if (!pressedFlag) {
    bleGamepad.press(btn);
    pressedFlag = true;
    startedFlag = millis();
  }
}

void releaseIfElapsed(int btn, bool &pressedFlag, uint32_t &startedFlag) {
  if (pressedFlag && (millis() - startedFlag >= (uint32_t)PRESS_MS)) {
    bleGamepad.release(btn);
    pressedFlag = false;
  }
}
Open the exact source-level diagram
ActionPress helper called
Action · NoPress the button and record the time
Result · YesLeave the current state unchanged

Technical notes

Encoder input

setupEncoder() handles physical input for translation into game-controller actions.

Button activation

tapButtonIfNeeded() handles button activation, with timing separate from the duration of the physical input.

Timed release

releaseIfElapsed() handles timed release to complete a button tap over the BLE interface.

Engineering archiveArchive record

Project enquiries

Discuss your project.

Tell us what you’re developing and where you need engineering support.

Discuss your project