USB Keyboard / MAME / Fight Stick / Pinball - Page 1
Forum section: electronics / projects

author: ApplePi
author_rank: Contributor
timestamp: March 01, 2016, 08:38:26 am
content: Here is a project I am currently working on. I've been enjoying old arcade games but I moved out from my parents place where I had my cabinet setup, so I decided I would do something different and give a 1P fight stick a go.The main goal of this project is to use some old Cherry MX switches in a USB HID Device that can be programmed for extra functionality. At the heart of this project is a Teensy 3.0/3.2 micro. I am currently awaiting most of the parts for it at this time so I decided to get some of the coding and test hardware fleshed out. Here is the fruit of that labor:https://imgur.com/a/bl9qdCode:#define REPEATRATE 100 // milliseconds#include <Bounce.h>Bounce button9 = Bounce(9, 10);const byte pin_P1_UP = 2;const byte pin_P1_DOWN = 3;const byte pin_P1_LEFT = 4;const byte pin_P1_RIGHT = 5;const byte pin_P1_B1 = 13;const byte pin_P1_B2 = 14;const byte pin_P1_B3 = 15;const byte pin_P1_B4 = 16;const byte pin_P1_B5 = 17;const byte pin_P1_B6 = 18;const byte pin_P1_START = 10;const byte pin_P1_COIN = 11;const byte pin_PAUSE = 12;const byte pin_SELECT = 6;const byte pin_CANCEL = 7;const byte pin_CONFIG = 8;const byte pin_LEDOutput = 23;int state;int maxstates = 2;byte buttons[] = {pin_P1_UP, pin_P1_DOWN, pin_P1_LEFT, pin_P1_RIGHT,pin_P1_B1, pin_P1_B2, pin_P1_B3, pin_P1_B4, pin_P1_B5, pin_P1_B6,pin_P1_START, pin_P1_COIN, pin_PAUSE, pin_SELECT, pin_CANCEL, pin_CONFIG};#define NUMBUTTONS sizeof(buttons)byte keys[sizeof(buttons)] = {{KEY_W, KEY_A, KEY_S, KEY_D,KEY_U, KEY_I, KEY_O, KEY_J, KEY_K, KEY_L,KEY_SPACE, KEY_5, KEY_P, KEY_ENTER, KEY_ESC, KEY_TAB},{KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT,KEY_A, KEY_S, KEY_D, KEY_Z, KEY_X, KEY_C,KEY_1, KEY_5, KEY_P, KEY_ENTER, KEY_ESC, KEY_TAB}};void setup(){pinMode(9, INPUT_PULLUP);pinMode( pin_LEDOutput, OUTPUT );for (byte i = 0; i < NUMBUTTONS; i++) {pinMode(buttons, INPUT_PULLUP);}}void loop(){button9.update();digitalWrite ( pin_LEDOutput, digitalRead(pin_P1_START));fcnProcessButtons();if (button9.fallingEdge()) {state = state + 1;}if (state >= maxstates){state = 0;}}void fcnProcessButtons(){static long currentkey = 0;byte nothingpressed = 1;for (byte i = 0; i < NUMBUTTONS; i++) {if (! digitalRead(buttons)) {nothingpressed = 0;if (currentkey != keys) {Keyboard.set_key1(0);Keyboard.send_now();Keyboard.set_key1(keys);currentkey = keys;Keyboard.send_now();}else {Keyboard.set_key1(keys);Keyboard.send_now();delay(REPEATRATE);}}}if (nothingpressed) {Keyboard.set_key1(0);Keyboard.send_now();}}For the housing of this project I will be using cut Plexiglas from Tek Innovations TEK-CASE S1-B with varying color florescent plexi, I'm opting for an 8 button top layout, 3 buttons on each side and 1 on the back for mode selection. For buttons I will be using HBFS-G2 30mm with Cherry MX White switches, they are a firm tactile bump with a click, they are no longer in production but I have a bag of them that I salvaged from an old keyboard that died. The color scheme for this build will be blue and green with UV LED lighting just to be silly. As for a joystick I will be using the Seimitsu LS-62-01, it's quite a bit shorter so it has a pretty short throw.Feel free to post any questions or comments and I will try to update this post as this build progresses.