Created
July 27, 2015 12:40
-
-
Save gregorykelleher/5185ff3c213fed9e4aeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <XBOXRECV.h> | |
// Satisfy IDE, which only needs to see the include statment in the ino. | |
#ifdef dobogusinclude | |
#include <spi4teensy3.h>u | |
#endif | |
USB Usb; | |
XBOXRECV Xbox(&Usb); | |
void setup() { | |
Serial.begin(115200); | |
pinMode( 7, OUTPUT); //vital to set pin 7 HIGH in order to work! | |
digitalWrite( 7, HIGH); | |
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection | |
if (Usb.Init() == -1) { | |
Serial.print(F("\r\nOSC did not start")); | |
while (1); //halt | |
} | |
Serial.print(F("\r\nXbox Wireless Receiver Library Started")); | |
} | |
void loop() { | |
Usb.Task(); | |
if (Xbox.XboxReceiverConnected) { | |
for (uint8_t i = 0; i < 4; i++) { | |
if (Xbox.Xbox360Connected[i]) { | |
int x = (Xbox.getAnalogHat(LeftHatX, i)); | |
int y = (Xbox.getAnalogHat(LeftHatY, i)); | |
if (x > 7500 || x < -7500 || y > 7500 || y < -7500) { | |
if(y > 7500) { | |
Serial.print("u"); //up | |
delay(20); | |
} | |
if(y < -7500) { | |
Serial.print("d"); //down | |
delay(20); | |
} | |
if(x < -7500) { | |
Serial.print("l"); //left | |
delay(20); | |
} | |
if(x > 7500) { | |
Serial.print("r"); //right | |
delay(20); | |
} | |
Serial.println(); | |
} | |
else if ( x < 7500 && x > -7500 && y < 7500 || y > -7500) { | |
Serial.print("s"); //stationary | |
Serial.println(); | |
} | |
int z = (Xbox.getAnalogHat(RightHatX, i)); | |
int v = (Xbox.getAnalogHat(RightHatY, i)); | |
if (z > 7500 || z < -7500 || v > 7500 || v < -7500) { | |
if(v > 7500) { | |
Serial.print("i"); //down | |
delay(20); | |
} | |
if(v < -7500) { | |
Serial.print("k"); //up | |
delay(20); | |
} | |
if(z < -7500) { | |
Serial.print("h"); //right | |
delay(20); | |
} | |
if(z > 7500) { | |
Serial.print("j"); //left | |
delay(20); | |
} | |
Serial.println(); | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment