Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.