Skip to content

Instantly share code, notes, and snippets.

@fvicente
Created September 13, 2015 01:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fvicente/515d08aabf5616f710cd to your computer and use it in GitHub Desktop.
Save fvicente/515d08aabf5616f710cd to your computer and use it in GitHub Desktop.
Arcade Joystick with Teensy 3.0
/* Arcade Keyboard-Joystick */
#include <usb_keyboard.h>
#define NUM_BUTTONS 8
int keys[NUM_BUTTONS] = {KEY_RIGHT, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_ENTER, KEY_SPACE, KEY_LEFT_ALT, KEY_Z};
int mask = 0;
int i = 0;
void setup() {
for (i = 0; i < NUM_BUTTONS; i++) {
pinMode(i, INPUT_PULLUP);
}
delay(1000);
}
void loop() {
for (i = 0; i < NUM_BUTTONS; i++) {
if (digitalRead(i) == LOW) {
if (!(mask & (1 << i))) {
Keyboard.press(keys[i] | (0x40 << 8));
mask |= (1 << i);
}
} else {
if ((mask & (1 << i))) {
Keyboard.release(keys[i] | (0x40 << 8));
mask &= ~(1 << i);
}
}
}
delay(2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment