2012-12-28 06:37:42 +01:00
|
|
|
/*
|
|
|
|
Example sketch for the Xbox Wireless Reciver library - developed by Kristian Lauszus
|
2012-12-29 14:15:40 +01:00
|
|
|
It supports up to four controllers wirelessly
|
2013-11-11 00:38:56 +01:00
|
|
|
For more information see the blog post: http://blog.tkjelectronics.dk/2012/12/xbox-360-receiver-added-to-the-usb-host-library/ or
|
2012-12-28 06:37:42 +01:00
|
|
|
send me an e-mail: kristianl@tkjelectronics.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <XBOXRECV.h>
|
2013-12-05 03:56:06 +01:00
|
|
|
// Satisfy IDE, which only needs to see the include statment in the ino.
|
|
|
|
#ifdef dobogusinclude
|
|
|
|
#include <spi4teensy3.h>
|
|
|
|
#endif
|
2013-10-02 00:49:46 +02:00
|
|
|
|
2012-12-28 06:37:42 +01:00
|
|
|
USB Usb;
|
|
|
|
XBOXRECV Xbox(&Usb);
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
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
|
2012-12-28 06:37:42 +01:00
|
|
|
if (Usb.Init() == -1) {
|
|
|
|
Serial.print(F("\r\nOSC did not start"));
|
2013-11-11 00:38:56 +01:00
|
|
|
while (1); //halt
|
2012-12-28 06:37:42 +01:00
|
|
|
}
|
|
|
|
Serial.print(F("\r\nXbox Wireless Receiver Library Started"));
|
|
|
|
}
|
|
|
|
void loop() {
|
|
|
|
Usb.Task();
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.XboxReceiverConnected) {
|
|
|
|
for (uint8_t i = 0; i < 4; i++) {
|
|
|
|
if (Xbox.Xbox360Connected[i]) {
|
|
|
|
if (Xbox.getButtonPress(L2, i) || Xbox.getButtonPress(R2, i)) {
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.print("L2: ");
|
2013-11-11 00:38:56 +01:00
|
|
|
Serial.print(Xbox.getButtonPress(L2, i));
|
2013-01-06 03:32:13 +01:00
|
|
|
Serial.print("\tR2: ");
|
2013-11-11 00:38:56 +01:00
|
|
|
Serial.println(Xbox.getButtonPress(R2, i));
|
|
|
|
Xbox.setRumbleOn(Xbox.getButtonPress(L2, i), Xbox.getButtonPress(R2, i), i);
|
2012-12-28 06:37:42 +01:00
|
|
|
}
|
2013-11-15 23:30:16 +01:00
|
|
|
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getAnalogHat(LeftHatX, i) > 7500 || Xbox.getAnalogHat(LeftHatX, i) < -7500 || Xbox.getAnalogHat(LeftHatY, i) > 7500 || Xbox.getAnalogHat(LeftHatY, i) < -7500 || Xbox.getAnalogHat(RightHatX, i) > 7500 || Xbox.getAnalogHat(RightHatX, i) < -7500 || Xbox.getAnalogHat(RightHatY, i) > 7500 || Xbox.getAnalogHat(RightHatY, i) < -7500) {
|
|
|
|
if (Xbox.getAnalogHat(LeftHatX, i) > 7500 || Xbox.getAnalogHat(LeftHatX, i) < -7500) {
|
|
|
|
Serial.print(F("LeftHatX: "));
|
|
|
|
Serial.print(Xbox.getAnalogHat(LeftHatX, i));
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.print("\t");
|
2013-11-11 00:38:56 +01:00
|
|
|
}
|
|
|
|
if (Xbox.getAnalogHat(LeftHatY, i) > 7500 || Xbox.getAnalogHat(LeftHatY, i) < -7500) {
|
|
|
|
Serial.print(F("LeftHatY: "));
|
|
|
|
Serial.print(Xbox.getAnalogHat(LeftHatY, i));
|
|
|
|
Serial.print("\t");
|
|
|
|
}
|
|
|
|
if (Xbox.getAnalogHat(RightHatX, i) > 7500 || Xbox.getAnalogHat(RightHatX, i) < -7500) {
|
|
|
|
Serial.print(F("RightHatX: "));
|
|
|
|
Serial.print(Xbox.getAnalogHat(RightHatX, i));
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.print("\t");
|
2013-11-11 00:38:56 +01:00
|
|
|
}
|
|
|
|
if (Xbox.getAnalogHat(RightHatY, i) > 7500 || Xbox.getAnalogHat(RightHatY, i) < -7500) {
|
|
|
|
Serial.print(F("RightHatY: "));
|
|
|
|
Serial.print(Xbox.getAnalogHat(RightHatY, i));
|
2012-12-28 06:37:42 +01:00
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(UP, i)) {
|
|
|
|
Xbox.setLedOn(LED1, i);
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("Up"));
|
2013-11-11 00:38:56 +01:00
|
|
|
}
|
|
|
|
if (Xbox.getButtonClick(DOWN, i)) {
|
|
|
|
Xbox.setLedOn(LED4, i);
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("Down"));
|
|
|
|
}
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(LEFT, i)) {
|
|
|
|
Xbox.setLedOn(LED3, i);
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("Left"));
|
|
|
|
}
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(RIGHT, i)) {
|
|
|
|
Xbox.setLedOn(LED2, i);
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("Right"));
|
2013-11-11 00:38:56 +01:00
|
|
|
}
|
2012-12-28 06:37:42 +01:00
|
|
|
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(START, i)) {
|
|
|
|
Xbox.setLedMode(ALTERNATING, i);
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("Start"));
|
|
|
|
}
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(BACK, i)) {
|
|
|
|
Xbox.setLedBlink(ALL, i);
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("Back"));
|
|
|
|
}
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(L3, i))
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("L3"));
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(R3, i))
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("R3"));
|
|
|
|
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(L1, i))
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("L1"));
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(R1, i))
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("R1"));
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(XBOX, i)) {
|
|
|
|
Xbox.setLedMode(ROTATING, i);
|
2013-01-06 03:32:13 +01:00
|
|
|
Serial.print(F("Xbox (Battery: "));
|
2013-04-15 18:36:47 +02:00
|
|
|
Serial.print(Xbox.getBatteryLevel(i)); // The battery level in the range 0-3
|
|
|
|
Serial.println(F(")"));
|
2012-12-28 06:37:42 +01:00
|
|
|
}
|
2013-11-11 00:43:18 +01:00
|
|
|
if (Xbox.getButtonClick(SYNC, i)) {
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("Sync"));
|
2013-11-11 00:43:18 +01:00
|
|
|
Xbox.disconnect(i);
|
|
|
|
}
|
2012-12-28 06:37:42 +01:00
|
|
|
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(A, i))
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("A"));
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(B, i))
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("B"));
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(X, i))
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("X"));
|
2013-11-11 00:38:56 +01:00
|
|
|
if (Xbox.getButtonClick(Y, i))
|
2012-12-28 06:37:42 +01:00
|
|
|
Serial.println(F("Y"));
|
|
|
|
}
|
|
|
|
}
|
2013-11-11 00:38:56 +01:00
|
|
|
}
|
2012-12-28 06:37:42 +01:00
|
|
|
}
|