Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Cheaper, simpler, more flexible control board solution - Arduino based  (Read 1014 times)

0 Members and 1 Guest are viewing this topic.

gschade

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 1
  • Last login:August 21, 2017, 05:42:01 pm
  • I want to build my own arcade controls!
Hi all, first post.

Bought a bunch of arcade controls to mess around with off ebay.  I was planning to use a Kade, but the board I ordered was shipping from Singapore or some nonsense and I think I won't get if for a few more weeks.   I had a couple of Arduinos and figured the hardware is basically the same.  So I threw together the following sketch.  Hooked up my joystick and buttons and happilly started playing Donkey Kong and Pitfall!

I actually think this might be better than the $10 zero delay interfaces on ebay (it uses a pretty mature debounce library).  Also, I see no reason you couldn't use this for a trackball, spinner, steering, etc. 

I used a leonardo which is why I can use USB;  If you wanted to use a cheaper nano or a UNO, you could use a PS2 interface instead.  You could use a Mega if you needed more pins for more buttons / joysticks (leonardo has 20 pins)

Also there is a joystick library out there for the Leonardo, so you could simulate joysticks easilly.

Anyone have any feedback?  How to make it better?  I am not a pro coder, so I'm sure my code is pretty craptastic, but it gets the job done.

I will update as I try other interfaces.  I have a shifter, Star Wars yoke and a spinner I plan to interface.

Code: [Select]
// Include the Bounce2 library found here :
// https://github.com/thomasfredericks/Bounce-Arduino-Wiring
#include <Bounce2.h>

int upB = 4;   // connect joystick and button controls to pins:  2=right, 3=down, 4=up, 5=left, 6=fire
int downB = 3;   // 2=right, 3=down, 4=up, 5=left, 6=fire
int leftB = 5;   // 2=right, 3=down, 4=up, 5=left, 6=fire
int rightB = 2;   // 2=right, 3=down, 4=up, 5=left, 6=fire
int fireB = 6;   // 2=right, 3=down, 4=up, 5=left, 6=fire

// Instantiate Bounce objects
Bounce debouncerFire = Bounce();
Bounce debouncerUp = Bounce();
Bounce debouncerDown = Bounce();
Bounce debouncerLeft = Bounce();
Bounce debouncerRight = Bounce();

void setup()
{

  Keyboard.begin();

  // Setup buttons with  internal pull-up :
  pinMode(fireB,INPUT_PULLUP);
  debouncerFire.attach(fireB);
  debouncerFire.interval(5); // interval in ms

  pinMode(upB,INPUT_PULLUP);
  debouncerUp.attach(upB);
  debouncerUp.interval(5); // interval in ms

  pinMode(downB,INPUT_PULLUP);
  debouncerDown.attach(downB);
  debouncerDown.interval(5); // interval in ms

  pinMode(leftB,INPUT_PULLUP);
  debouncerLeft.attach(leftB);
  debouncerLeft.interval(5); // interval in ms

  pinMode(rightB,INPUT_PULLUP);
  debouncerRight.attach(rightB);
  debouncerRight.interval(5); // interval in ms
  }

void loop()
{
 
  if (debouncerFire.update()) {
     if (debouncerFire.read()==LOW) {
      Keyboard.press(' ');
     }
      else {
      Keyboard.release(' ');                                                     
     }
  }
  if (debouncerRight.update()) {
     if (debouncerRight.read()==LOW) {
      Keyboard.press(KEY_RIGHT_ARROW);
     }
      else {
      Keyboard.release(KEY_RIGHT_ARROW);                                                     
     }
  }
  if (debouncerLeft.update()) {
     if (debouncerLeft.read()==LOW) {
      Keyboard.press(KEY_LEFT_ARROW);
     }
      else {
      Keyboard.release(KEY_LEFT_ARROW);                                                     
     }
  }
  if (debouncerUp.update()) {
     if (debouncerUp.read()==LOW) {
      Keyboard.press(KEY_UP_ARROW);
     }
      else {
      Keyboard.release(KEY_UP_ARROW);                                                     
     }
  }
  if (debouncerDown.update()) {
     if (debouncerDown.read()==LOW) {
      Keyboard.press(KEY_DOWN_ARROW);
     }
      else {
      Keyboard.release(KEY_DOWN_ARROW);                                                     
     }
  }

}
« Last Edit: December 14, 2015, 08:53:05 pm by gschade »