Arcade Buttons

KinectSandbox is prepared to handle arcade buttons. Some software functions are fixed to the keyboard and mouse keys. For example, a single button press drains water on the interactive map. This function is fixed to mouse button 2. We can use arcade buttons instead of pressing keys on the keyboard. For this we will use Arduino Leonardo/Micro pro development board. Arduino will simulate the keyboard in the computer system.


Here is what you will need:

  • Arcade buttons,
  • 10k resistors,
  • 1x Arduino board,
  • 1x USB cable (micro USB – USB or USB C – USB),
  • Soldering station;
Circuit diagram

Connect buttons from 1 up to 12. First button is for application control (mouse 2 and mouse 3 buttons) and others can be used to change predefined presets (simulating keys 0-9)

Download ARDUINO IDE https://www.arduino.cc/en/software

  1. Run Arduino IDE;
  2. Go to Tools > Manage Libraries;
  3. Find library “Bounce2” and install;
  4. Find library “Keyboard” and install;
  5. Find library “Mouse” and install;
  6. Download code below and upload to the board. (default values for Micro PRO, for Leonardo change pinout in code)

Code for single Arcade Button

#include <Keyboard.h>  
#include <Bounce2.h>
#include <Mouse.h>
// ARDUINO for boards
// Leonardo https://www.arduino.cc/en/Main/Arduino_BoardLeonardo
// Micro Pro eg. https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro
// Button pin 2, resitor 10k Ohm

int sensorPin1 = 2;   
Bounce debouncer = Bounce(); 

int sensorValue1 = 0;
int oldSensor = 0;
int but1=0;
int i=0;
int waspressed=0;

void setup() {
  pinMode(sensorPin1,INPUT_PULLUP);
  debouncer.attach(sensorPin1);
  debouncer.interval(25); // interval in ms
  Serial.begin(9600); 
}

void loop() {
  debouncer.update();
  sensorValue1 = debouncer.read();
  if (waspressed==1 && i == 100 ) {

      Serial.println("but2");
      Keyboard.write('b');
      //Mouse.click(MOUSE_LEFT); // only up to KinectSandbox 1.9.8
      //Mouse.click(MOUSE_MIDDLE); // since KinectSandbox 1.9.9 
       waspressed=0; 
    
    }    

  if (waspressed==1 && sensorValue1 == LOW && i <100) {

      Serial.println("but1");
      Keyboard.write(' ');
      //Mouse.click(MOUSE_LEFT); // only up to KinectSandbox 1.9.8
      //Mouse.click(MOUSE_MIDDLE); // since KinectSandbox 1.9.9
        
    }   
 
 if (oldSensor == HIGH && sensorValue1 == HIGH) {
  i++;
  waspressed=1; 
  }
  else {
    i=0;
    waspressed=0;
 }
  

oldSensor=sensorValue1;


delay(20);

}