XBOX360コントローラをArduinoでJAMMAにする

XBOX360コントローラをUSB Host LibraryをつかってArduino MEGA 2560でJAMMAにする

https://github.com/felis/USB_Host_Shield_2.0

XBOXUSB.ino

/*
 Example sketch for the Xbox 360 USB library - developed by Kristian Lauszus
 For more information visit my blog: http://blog.tkjelectronics.dk/ or
 send me an e-mail:  kristianl@tkjelectronics.com
 */

#include <XBOXUSB.h>

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif

USB Usb;
XBOXUSB Xbox(&Usb);

/*
  The following values will be used as digital inputs
  for each specific iCade function.
*/

void setup() {
  Serial.begin(115200);
#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start\n"));
    while (1); //halt
  }

  for (int thisPin=2; thisPin < 15; thisPin++ )
  {
    pinMode(thisPin, OUTPUT);
  }

  Serial.print(F("\r\nXBOX USB Library Started\n"));
}
void loop() {
  Usb.Task();
  if (Xbox.Xbox360Connected) {
    if (Xbox.getButtonPress(BACK)) {
      Serial.println(F("Back"));
      digitalWrite(2, LOW);
    } else {
      digitalWrite(2, HIGH);
    }
    if (Xbox.getButtonPress(START)) {
      Serial.println(F("Start"));
      digitalWrite(3, LOW);
    } else {
      digitalWrite(3, HIGH);
    }
    if (Xbox.getButtonPress(UP)) {
      Serial.println(F("Up"));
      digitalWrite(4, LOW);
    } else {
      digitalWrite(4, HIGH);
    }
    if (Xbox.getButtonPress(DOWN)) {
      Serial.println(F("Down"));
      digitalWrite(5, LOW);
    } else {
      digitalWrite(5, HIGH);
    }
    if (Xbox.getButtonPress(LEFT)) {
      Serial.println(F("Left"));
      digitalWrite(6, LOW);
    } else {
      digitalWrite(6, HIGH);
    }
    if (Xbox.getButtonPress(RIGHT)) {
      Serial.println(F("Right"));
      digitalWrite(7, LOW);
    } else {
      digitalWrite(7, HIGH);
    }
    if (Xbox.getButtonPress(L1)) {
      Serial.println(F("L1"));
      digitalWrite(8, LOW);
    } else {
      digitalWrite(8, HIGH);
    }
    if (Xbox.getButtonPress(X)) {
      Serial.println(F("X"));
      digitalWrite(9, LOW);
    } else {
      digitalWrite(9, HIGH);
    }
    if (Xbox.getButtonPress(Y)) {
      Serial.println(F("Y"));
      digitalWrite(14, LOW);
    } else {
      digitalWrite(14, HIGH);
    }
    if (Xbox.getButtonPress(R1)) {
      Serial.println(F("R1"));
      digitalWrite(11, LOW);
    } else {
      digitalWrite(11, HIGH);
    }
    if (Xbox.getButtonPress(A)) {
      Serial.println(F("A"));
      digitalWrite(12, LOW);
    } else {
      digitalWrite(12, HIGH);
    }
    if (Xbox.getButtonPress(B)) {
      Serial.println(F("B"));
      digitalWrite(13, LOW);
    } else {
      digitalWrite(13, HIGH);
    }
  }
  delay(1);
}