2013-07-18 17:52:23 +02:00
|
|
|
/*
|
|
|
|
Example sketch for the original Xbox library - developed by Kristian Lauszus
|
2013-11-15 19:05:25 +01:00
|
|
|
For more information visit my blog: http://blog.tkjelectronics.dk/ or
|
2013-07-18 17:52:23 +02:00
|
|
|
send me an e-mail: kristianl@tkjelectronics.com
|
|
|
|
*/
|
|
|
|
|
2013-07-18 20:35:23 +02:00
|
|
|
#include <XBOXOLD.h>
|
2013-07-18 20:52:06 +02:00
|
|
|
#include <usbhub.h>
|
2014-08-03 00:57:37 +02:00
|
|
|
|
2015-03-03 19:08:39 +01:00
|
|
|
// Satisfy the IDE, which needs to see the include statment in the ino too.
|
|
|
|
#ifdef dobogusinclude
|
2013-12-05 03:56:06 +01:00
|
|
|
#include <spi4teensy3.h>
|
|
|
|
#endif
|
2017-08-14 09:39:38 +02:00
|
|
|
#include <SPI.h>
|
2013-07-18 20:52:06 +02:00
|
|
|
|
2013-07-18 17:52:23 +02:00
|
|
|
USB Usb;
|
2013-07-18 20:52:06 +02:00
|
|
|
USBHub Hub1(&Usb); // The controller has a built in hub, so this instance is needed
|
2013-07-18 20:35:23 +02:00
|
|
|
XBOXOLD Xbox(&Usb);
|
2013-07-18 17:52:23 +02:00
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
2014-11-10 07:35:13 +01:00
|
|
|
#if !defined(__MIPSEL__)
|
2013-10-21 19:58:03 +02:00
|
|
|
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
|
2014-11-10 07:35:13 +01:00
|
|
|
#endif
|
2013-07-18 17:52:23 +02:00
|
|
|
if (Usb.Init() == -1) {
|
|
|
|
Serial.print(F("\r\nOSC did not start"));
|
2013-11-15 19:05:25 +01:00
|
|
|
while (1); // halt
|
|
|
|
}
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.print(F("\r\nXBOX Library Started"));
|
|
|
|
}
|
|
|
|
void loop() {
|
|
|
|
Usb.Task();
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.XboxConnected) {
|
|
|
|
if (Xbox.getButtonPress(BLACK) || Xbox.getButtonPress(WHITE)) {
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.print("BLACK: ");
|
|
|
|
Serial.print(Xbox.getButtonPress(BLACK));
|
|
|
|
Serial.print("\tWHITE: ");
|
|
|
|
Serial.println(Xbox.getButtonPress(WHITE));
|
2013-11-15 19:05:25 +01:00
|
|
|
Xbox.setRumbleOn(Xbox.getButtonPress(BLACK), Xbox.getButtonPress(WHITE));
|
2013-07-18 17:52:23 +02:00
|
|
|
} else
|
2013-11-15 19:05:25 +01:00
|
|
|
Xbox.setRumbleOn(0, 0);
|
2013-11-15 23:30:16 +01:00
|
|
|
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500 || Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500 || Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500 || Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) {
|
|
|
|
if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) {
|
|
|
|
Serial.print(F("LeftHatX: "));
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.print(Xbox.getAnalogHat(LeftHatX));
|
|
|
|
Serial.print("\t");
|
2013-11-15 19:05:25 +01:00
|
|
|
}
|
|
|
|
if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) {
|
|
|
|
Serial.print(F("LeftHatY: "));
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.print(Xbox.getAnalogHat(LeftHatY));
|
|
|
|
Serial.print("\t");
|
2013-11-15 19:05:25 +01:00
|
|
|
}
|
|
|
|
if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) {
|
|
|
|
Serial.print(F("RightHatX: "));
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.print(Xbox.getAnalogHat(RightHatX));
|
2013-11-15 19:05:25 +01:00
|
|
|
Serial.print("\t");
|
|
|
|
}
|
|
|
|
if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) {
|
|
|
|
Serial.print(F("RightHatY: "));
|
|
|
|
Serial.print(Xbox.getAnalogHat(RightHatY));
|
2013-07-18 17:52:23 +02:00
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
}
|
2013-11-15 19:05:25 +01:00
|
|
|
|
|
|
|
if (Xbox.getButtonClick(UP))
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.println(F("Up"));
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonClick(DOWN))
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.println(F("Down"));
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonClick(LEFT))
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.println(F("Left"));
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonClick(RIGHT))
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.println(F("Right"));
|
|
|
|
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonClick(START))
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.println(F("Start"));
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonClick(BACK))
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.println(F("Back"));
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonClick(L3))
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.println(F("L3"));
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonClick(R3))
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.println(F("R3"));
|
|
|
|
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonPress(A)) {
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.print(F("A: "));
|
|
|
|
Serial.println(Xbox.getButtonPress(A));
|
|
|
|
}
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonPress(B)) {
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.print(F("B: "));
|
|
|
|
Serial.println(Xbox.getButtonPress(B));
|
|
|
|
}
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonPress(X)) {
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.print(F("X: "));
|
|
|
|
Serial.println(Xbox.getButtonPress(X));
|
|
|
|
}
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonPress(Y)) {
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.print(F("Y: "));
|
|
|
|
Serial.println(Xbox.getButtonPress(Y));
|
|
|
|
}
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonPress(L1)) {
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.print(F("L1: "));
|
|
|
|
Serial.println(Xbox.getButtonPress(L1));
|
|
|
|
}
|
2013-11-15 19:05:25 +01:00
|
|
|
if (Xbox.getButtonPress(R1)) {
|
2013-07-18 17:52:23 +02:00
|
|
|
Serial.print(F("R1: "));
|
|
|
|
Serial.println(Xbox.getButtonPress(R1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delay(1);
|
|
|
|
}
|