7 years, 11 months ago.

Need help regarding using USBKeyboard with InterruptIn

Hello guys! I'm new in C++ programming, picked it up for school project purposes. So I am to use mbed to emulate USBKeyboard for gaming purposes (yes, I am trying to create something like a joystick/controller for pc gaming). So I wrote the following program with the limited programming knowledge I have.

Currently testing it with push buttons mounted on breadboard. My problem is, once you've pressed a single button, the text would print non-stop, no matter what program you're on (note pad, browser, word document, mbed compiler etc). It works on games like I intended, however the game character would just keep running in one single direction. Pressing other buttons wouldn't change its state, and it only stops when I press the reset button on mbed.

I've connected the pins like the guys did in this video

I'm guessing the problem lies with the interrupt or that the USBKeyboard library isn't compatible with interrupt. Are there any ways to break the interrupt? Please advise, thanks you!

P.S. I only used the standard a & d (left and right) button for testing purposes before putting in more inputs.

#include "mbed.h"
#include "USBKeyboard.h"

USBKeyboard keyboard;

InterruptIn a(p23);
InterruptIn d(p24);

DigitalOut myled(LED2);

void ai ()

void di ()

int main(void)
    while (1) {
    myled = !myled;

I would expect that that would work, so the obvious first question: Does it work when you don't use interrupts?

posted by Erik - 23 May 2013

Yes it does, but movement in game wasn't smooth. Instead of the normal running animation, you see the character sliding instead.

posted by Reiry Chrysler 27 May 2013
Be the first to answer this question.