USB Arcade stick using a Teensy LC for Mame

These arcade controls have been through at least 4 projects at this stage and have had little or no real use. The last incarnation had a retropie installation on a Raspberry pi 3 inside which I now need for another project.

I've also had the Teensy LC sitting in a box doing very little for the 3 years I've had it so I thought I'd kill 2 birds and reuse the RasPi and put the Teensy to some good use. Also means we can use the arcade stick on any laptop/PC we have.


Primary use for the stick will be for Mame/SNES/Sega emulation. It will be configured as a keyboard so it will easy to configure each of the emulators to use as if just using a keyboard.

The box has a total of 14 buttons.

4 for the directions
6 for general buttons
1 Start
1 Select
2 Pushbuttons on the back which will be configured for ESC and another free.

The Teensy Sketch

The sketch itself is very simple. The Teensy is setup as a standard keyboard input and we enable the first 14 inputs (0-13) with internal pullups so the are active low when pressed. The Bounce.h debouncing library ensures we remove any unwanted presses from the buttons.

On detection of a button press we use:

if (button1.fallingEdge()) {;

Once the button is released we do the opposite

if (button1.fallingEdge()) {
/* USB Arcade Stick 
 *  All Buttons assigned as Keyboard keys for easy use with Emulation
 * Original code from the Teensy Examples. 


// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10);  // 10 = 10 ms debounce time
Bounce button2 = Bounce(2, 10);  // which is appropriate for
Bounce button3 = Bounce(3, 10);  // most mechanical pushbuttons
Bounce button4 = Bounce(4, 10);
Bounce button5 = Bounce(5, 10);  // if a button is too "sensitive"
Bounce button6 = Bounce(6, 10);  // to rapid touch, you can
Bounce button7 = Bounce(7, 10);  // increase this time.
Bounce button8 = Bounce(8, 10);
Bounce button9 = Bounce(9, 10);
Bounce button10 = Bounce(10, 10);
Bounce button11 = Bounce(11, 10);
Bounce button12 = Bounce(12, 10);
Bounce button13 = Bounce(13, 10);

void setup() {
  // Configure the pins for input mode with pullup resistors.
  // The pushbuttons connect from each pin to ground.  When
  // the button is pressed, the pin reads LOW because the button
  // shorts it to ground.  When released, the pin reads HIGH
  // because the pullup resistor connects to +5 volts inside
  // the chip.  LOW for "on", and HIGH for "off" may seem
  // backwards, but using the on-chip pullup resistors is very
  // convenient.  The scheme is called "active low", and it's
  // very commonly used in electronics... so much that the chip
  // has built-in pullup resistors!
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);  // Teensy++ LED, may need 1k resistor pullup
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);

void loop() {
  // Update all the buttons.  There should not be any long
  // delays in loop(), so this runs repetitively at a rate
  // faster than the buttons could be pressed and released.

  // Check each button for "falling" edge.
  // Type a message on the Keyboard when each button presses
  // Update the Joystick buttons only upon changes.
  // falling = high (not pressed - voltage from pullup resistor)
  //           to low (pressed - button connects pin to ground)
  if (button0.fallingEdge()) {;
  if (button1.fallingEdge()) {;
  if (button2.fallingEdge()) {;
  if (button3.fallingEdge()) {;
  if (button4.fallingEdge()) {;
  if (button5.fallingEdge()) {;
  if (button6.fallingEdge()) {;
  if (button7.fallingEdge()) {;
  if (button8.fallingEdge()) {;
  if (button9.fallingEdge()) {;
  if (button10.fallingEdge()) {;
  if (button11.fallingEdge()) {;
  if (button12.fallingEdge()) {;
  if (button13.fallingEdge()) {;

  // Check each button for "rising" edge
  // Type a message on the Keyboard when each button releases.
  // For many types of projects, you only care when the button
  // is pressed and the release isn't needed.
  // rising = low (pressed - button connects pin to ground)
  //          to high (not pressed - voltage from pullup resistor)
  if (button0.risingEdge()) {
  if (button1.risingEdge()) {
  if (button2.risingEdge()) {
  if (button3.risingEdge()) {
  if (button4.risingEdge()) {
  if (button5.risingEdge()) {
  if (button6.risingEdge()) {
  if (button7.risingEdge()) {
  if (button8.risingEdge()) {
  if (button9.risingEdge()) {
  if (button10.risingEdge()) {
  if (button11.risingEdge()) {
  if (button12.risingEdge()) {
  if (button13.risingEdge()) {

Key Assignments

Pin Code Function
0 KEY_LEFT Joy Left
1 KEY_UP Joy Up
2 KEY_DOWN Joy Down
3 KEY_RIGHT Joy Right
4 KEY_5 Insert Coin P1
5 KEY_1 Start P1
6 KEY_Z Button 1
7 KEY_X Button 2
8 KEY_C Button 3
9 KEY_A Button 4
10 KEY_S Button 5
11 KEY_D Button 6
12 KEY_ESC Escape
13 KEY_F Free

Leave a Reply