Created
September 13, 2015 01:56
-
-
Save fvicente/515d08aabf5616f710cd to your computer and use it in GitHub Desktop.
Arcade Joystick with Teensy 3.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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