Created
June 27, 2015 07:15
-
-
Save Oliv4945/efceb2126e67bf86db63 to your computer and use it in GitHub Desktop.
Code borne Arcade LOG
This file contains 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 */ | |
#define NUM_BUTTONS 24 | |
int keys[NUM_BUTTONS] = {KEY_RIGHT, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_ENTER, MODIFIERKEY_SHIFT, KEY_A, KEY_S, KEY_Z, KEY_X, KEY_Q, KEY_W, KEY_1, KEY_2, KEY_4, KEY_5, KEY_7, KEY_8, KEY_9, KEY_R, KEY_O, KEY_V, KEY_B, KEY_C}; | |
long mask = 0; | |
int i = 0; | |
void setup() { | |
Serial.begin(115200); // USB is always 12 Mbit/sec | |
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); | |
Serial.print(i); | |
Serial.print(" - "); | |
Serial.println(keys[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