hey everyone i've been tearing my hair out trying to get my arduino pro micro (atmega32u4) to work as a controller for my pi zero 2 w running retropie-i'm using Bounc2 for debounce and wiring buttons straight gnd→button→pin (no diodes or matrix) but every time i play a game (e.g. pokemon) and press A it instantly fires B too and deletes the letter i just picked i've tried Keyboard.releaseAll each loop which stopped the ghosting but broke holding, i've tried tracking pressed states with bool arrays and only doing Keyboard.release(mapping[i].key) on rose(), i've tried blocking B for 300ms after A with millis checks, i've tweaked debounce intervals and loop delays-nothing works in‑game it still ghosts B after A and i'm totally stumped any ideas or pointers? thank you in advance! here's my current sketch:
#include <Keyboard.h>
#include <Bounce2.h>
// Pin definitions
const uint8_t PIN_DOWN = 2;
const uint8_t PIN_UP = 3;
const uint8_t PIN_RIGHT = 4;
const uint8_t PIN_LEFT = 5;
const uint8_t PIN_SELECT = 6;
const uint8_t PIN_START = 7;
const uint8_t PIN_B = 8;
const uint8_t PIN_A = 9;
const uint8_t PIN_HOTKEY = 10;
// Pin → key mapping
struct { uint8_t pin, key; } mapping[] = {
{PIN_UP, KEY_UP_ARROW},
{PIN_DOWN, KEY_DOWN_ARROW},
{PIN_LEFT, KEY_LEFT_ARROW},
{PIN_RIGHT, KEY_RIGHT_ARROW},
{PIN_SELECT, ' '},
{PIN_START, KEY_RETURN},
{PIN_B, 'b'},
{PIN_A, 'a'},
{PIN_HOTKEY, 'h'},
};
static const size_t NUM_BTN = sizeof(mapping)/sizeof(mapping[0]);
Bounce debouncers[NUM_BTN];
bool pressed[NUM_BTN] = {0};
uint32_t lastATime = 0;
const uint16_t BLOCK_B_MS = 300;
void setup() {
Keyboard.begin();
for (size_t i = 0; i < NUM_BTN; i++) {
pinMode(mapping[i].pin, INPUT_PULLUP);
debouncers[i].attach(mapping[i].pin);
debouncers[i].interval(50);
}
}
void loop() {
for (size_t i = 0; i < NUM_BTN; i++) {
debouncers[i].update();
// Press
if (debouncers[i].fell()) {
uint8_t k = mapping[i].key;
if (k == 'a') {
lastATime = millis();
Keyboard.press(k);
pressed[i] = true;
}
else if (k == 'b') {
if (millis() - lastATime > BLOCK_B_MS) {
Keyboard.press(k);
pressed[i] = true;
}
}
else {
Keyboard.press(k);
pressed[i] = true;
}
}
// Release
if (debouncers[i].rose() && pressed[i]) {
Keyboard.release(mapping[i].key);
pressed[i] = false;
}
}
delay(10);
}