Updated formatting

This commit is contained in:
Kristian Lauszus 2013-11-15 19:05:25 +01:00
parent b50919b077
commit 87cb83276b
10 changed files with 313 additions and 313 deletions

View file

@ -1,7 +1,7 @@
/*
Example sketch for the PS3 Bluetooth library - developed by Kristian Lauszus
This example show how one can use multiple controllers with the library
For more information visit my blog: http://blog.tkjelectronics.dk/ or
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
*/
@ -12,12 +12,12 @@ USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
PS3BT *PS3[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like, but it will use a lot of RAM!
const uint8_t length = sizeof(PS3)/sizeof(PS3[0]); // Get the lenght of the array
const uint8_t length = sizeof(PS3) / sizeof(PS3[0]); // Get the lenght of the array
boolean printAngle[length];
boolean oldControllerState[length];
void setup() {
for (uint8_t i=0;i<length;i++) {
for (uint8_t i = 0; i < length; i++) {
PS3[i] = new PS3BT(&Btd); // Create the instances
PS3[i]->attachOnInit(onInit); // onInit() is called upon a new connection - you can call the function whatever you like
}
@ -26,21 +26,21 @@ void setup() {
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
while (1); //halt
}
Serial.print(F("\r\nPS3 Bluetooth Library Started"));
}
void loop() {
Usb.Task();
for(uint8_t i=0;i<length;i++) {
if(PS3[i]->PS3Connected || PS3[i]->PS3NavigationConnected) {
if(PS3[i]->getAnalogHat(LeftHatX) > 137 || PS3[i]->getAnalogHat(LeftHatX) < 117 || PS3[i]->getAnalogHat(LeftHatY) > 137 || PS3[i]->getAnalogHat(LeftHatY) < 117 || PS3[i]->getAnalogHat(RightHatX) > 137 || PS3[i]->getAnalogHat(RightHatX) < 117 || PS3[i]->getAnalogHat(RightHatY) > 137 || PS3[i]->getAnalogHat(RightHatY) < 117) {
for (uint8_t i = 0; i < length; i++) {
if (PS3[i]->PS3Connected || PS3[i]->PS3NavigationConnected) {
if (PS3[i]->getAnalogHat(LeftHatX) > 137 || PS3[i]->getAnalogHat(LeftHatX) < 117 || PS3[i]->getAnalogHat(LeftHatY) > 137 || PS3[i]->getAnalogHat(LeftHatY) < 117 || PS3[i]->getAnalogHat(RightHatX) > 137 || PS3[i]->getAnalogHat(RightHatX) < 117 || PS3[i]->getAnalogHat(RightHatY) > 137 || PS3[i]->getAnalogHat(RightHatY) < 117) {
Serial.print(F("\r\nLeftHatX: "));
Serial.print(PS3[i]->getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: "));
Serial.print(PS3[i]->getAnalogHat(LeftHatY));
if(!PS3[i]->PS3NavigationConnected) { // The Navigation controller only have one joystick
if (!PS3[i]->PS3NavigationConnected) { // The Navigation controller only have one joystick
Serial.print(F("\tRightHatX: "));
Serial.print(PS3[i]->getAnalogHat(RightHatX));
Serial.print(F("\tRightHatY: "));
@ -48,77 +48,77 @@ void loop() {
}
}
//Analog button values can be read from almost all buttons
if(PS3[i]->getAnalogButton(L2) || PS3[i]->getAnalogButton(R2)) {
if (PS3[i]->getAnalogButton(L2) || PS3[i]->getAnalogButton(R2)) {
Serial.print(F("\r\nL2: "));
Serial.print(PS3[i]->getAnalogButton(L2));
if(!PS3[i]->PS3NavigationConnected) {
if (!PS3[i]->PS3NavigationConnected) {
Serial.print(F("\tR2: "));
Serial.print(PS3[i]->getAnalogButton(R2));
}
}
if(PS3[i]->getButtonClick(PS)) {
if (PS3[i]->getButtonClick(PS)) {
Serial.print(F("\r\nPS"));
PS3[i]->disconnect();
oldControllerState[i] = false; // Reset value
}
else {
if(PS3[i]->getButtonClick(TRIANGLE))
if (PS3[i]->getButtonClick(TRIANGLE))
Serial.print(F("\r\nTraingle"));
if(PS3[i]->getButtonClick(CIRCLE))
if (PS3[i]->getButtonClick(CIRCLE))
Serial.print(F("\r\nCircle"));
if(PS3[i]->getButtonClick(CROSS))
if (PS3[i]->getButtonClick(CROSS))
Serial.print(F("\r\nCross"));
if(PS3[i]->getButtonClick(SQUARE))
if (PS3[i]->getButtonClick(SQUARE))
Serial.print(F("\r\nSquare"));
if(PS3[i]->getButtonClick(UP)) {
if (PS3[i]->getButtonClick(UP)) {
Serial.print(F("\r\nUp"));
if(PS3[i]->PS3Connected) {
if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff();
PS3[i]->setLedOn(LED4);
}
}
if(PS3[i]->getButtonClick(RIGHT)) {
if (PS3[i]->getButtonClick(RIGHT)) {
Serial.print(F("\r\nRight"));
if(PS3[i]->PS3Connected) {
if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff();
PS3[i]->setLedOn(LED1);
}
}
if(PS3[i]->getButtonClick(DOWN)) {
if (PS3[i]->getButtonClick(DOWN)) {
Serial.print(F("\r\nDown"));
if(PS3[i]->PS3Connected) {
if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff();
PS3[i]->setLedOn(LED2);
}
}
if(PS3[i]->getButtonClick(LEFT)) {
if (PS3[i]->getButtonClick(LEFT)) {
Serial.print(F("\r\nLeft"));
if(PS3[i]->PS3Connected) {
if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff();
PS3[i]->setLedOn(LED3);
}
}
if(PS3[i]->getButtonClick(L1))
if (PS3[i]->getButtonClick(L1))
Serial.print(F("\r\nL1"));
if(PS3[i]->getButtonClick(L3))
if (PS3[i]->getButtonClick(L3))
Serial.print(F("\r\nL3"));
if(PS3[i]->getButtonClick(R1))
if (PS3[i]->getButtonClick(R1))
Serial.print(F("\r\nR1"));
if(PS3[i]->getButtonClick(R3))
if (PS3[i]->getButtonClick(R3))
Serial.print(F("\r\nR3"));
if(PS3[i]->getButtonClick(SELECT)) {
if (PS3[i]->getButtonClick(SELECT)) {
Serial.print(F("\r\nSelect - "));
Serial.print(PS3[i]->getStatusString());
}
if(PS3[i]->getButtonClick(START)) {
if (PS3[i]->getButtonClick(START)) {
Serial.print(F("\r\nStart"));
printAngle[i] = !printAngle[i];
}
}
if(printAngle[i]) {
if (printAngle[i]) {
Serial.print(F("\r\nPitch: "));
Serial.print(PS3[i]->getAngle(Pitch));
Serial.print(F("\tRoll: "));
@ -126,12 +126,12 @@ void loop() {
}
}
/* I have removed the PS3 Move code as an Uno will run out of RAM if it's included */
//else if(PS3[i]->PS3MoveConnected) {
//else if(PS3[i]->PS3MoveConnected) {
}
}
void onInit() {
for (uint8_t i=0;i<length;i++) {
for (uint8_t i = 0; i < length; i++) {
if ((PS3[i]->PS3Connected || PS3[i]->PS3NavigationConnected) && !oldControllerState[i]) {
oldControllerState[i] = true; // Used to check which is the new controller
PS3[i]->setLedOn((LED)i); // Cast directly to LED enum - see: "controllerEnums.h"

View file

@ -1,6 +1,6 @@
/*
Example sketch for the Bluetooth library - developed by Kristian Lauszus
For more information visit my blog: http://blog.tkjelectronics.dk/ or
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
This example show how one can combine all the difference Bluetooth services in one single code.
@ -31,7 +31,7 @@ void setup() {
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
while (1); //halt
}
Serial.print(F("\r\nBluetooth Library Started"));
output.reserve(200); // Reserve 200 bytes for the output string
@ -39,27 +39,27 @@ void setup() {
void loop() {
Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well
if(SerialBT.connected) {
if(firstMessage) {
if (SerialBT.connected) {
if (firstMessage) {
firstMessage = false;
SerialBT.println(F("Hello from Arduino")); // Send welcome message
}
if(Serial.available())
if (Serial.available())
SerialBT.write(Serial.read());
if(SerialBT.available())
if (SerialBT.available())
Serial.write(SerialBT.read());
}
else
}
else
firstMessage = true;
if(PS3.PS3Connected || PS3.PS3NavigationConnected) {
if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
output = ""; // Reset output string
if(PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) {
if (PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117) {
output += "LeftHatX: ";
output += PS3.getAnalogHat(LeftHatX);
output += "\tLeftHatY: ";
output += PS3.getAnalogHat(LeftHatY);
if(!PS3.PS3NavigationConnected) {
if (!PS3.PS3NavigationConnected) {
output += "\tRightHatX: ";
output += PS3.getAnalogHat(RightHatX);
output += "\tRightHatY: ";
@ -67,85 +67,85 @@ void loop() {
}
}
//Analog button values can be read from almost all buttons
if(PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
if(output != "")
if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
if (output != "")
output += "\r\n";
output += "L2: ";
output += PS3.getAnalogButton(L2);
if(!PS3.PS3NavigationConnected) {
if (!PS3.PS3NavigationConnected) {
output += "\tR2: ";
output += PS3.getAnalogButton(R2);
}
}
}
if(output != "") {
if (output != "") {
Serial.println(output);
if(SerialBT.connected)
if (SerialBT.connected)
SerialBT.println(output);
output = ""; // Reset output string
}
if(PS3.getButtonClick(PS)) {
if (PS3.getButtonClick(PS)) {
output += " - PS";
PS3.disconnect();
}
}
else {
if(PS3.getButtonClick(TRIANGLE))
if (PS3.getButtonClick(TRIANGLE))
output += " - Traingle";
if(PS3.getButtonClick(CIRCLE))
if (PS3.getButtonClick(CIRCLE))
output += " - Circle";
if(PS3.getButtonClick(CROSS))
if (PS3.getButtonClick(CROSS))
output += " - Cross";
if(PS3.getButtonClick(SQUARE))
if (PS3.getButtonClick(SQUARE))
output += " - Square";
if(PS3.getButtonClick(UP)) {
if (PS3.getButtonClick(UP)) {
output += " - Up";
if(PS3.PS3Connected) {
if (PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED4);
}
}
if(PS3.getButtonClick(RIGHT)) {
}
if (PS3.getButtonClick(RIGHT)) {
output += " - Right";
if(PS3.PS3Connected) {
if (PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED1);
}
}
if(PS3.getButtonClick(DOWN)) {
output += " - Down";
if(PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED2);
PS3.setLedOn(LED1);
}
}
if(PS3.getButtonClick(LEFT)) {
output += " - Left";
if(PS3.PS3Connected) {
}
if (PS3.getButtonClick(DOWN)) {
output += " - Down";
if (PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED2);
}
}
if (PS3.getButtonClick(LEFT)) {
output += " - Left";
if (PS3.PS3Connected) {
PS3.setAllOff();
PS3.setLedOn(LED3);
}
}
PS3.setLedOn(LED3);
}
}
if(PS3.getButtonClick(L1))
if (PS3.getButtonClick(L1))
output += " - L1";
if(PS3.getButtonClick(L3))
output += " - L3";
if(PS3.getButtonClick(R1))
output += " - R1";
if(PS3.getButtonClick(R3))
output += " - R3";
if (PS3.getButtonClick(L3))
output += " - L3";
if (PS3.getButtonClick(R1))
output += " - R1";
if (PS3.getButtonClick(R3))
output += " - R3";
if(PS3.getButtonClick(SELECT)) {
if (PS3.getButtonClick(SELECT)) {
output += " - Select - ";
output += PS3.getStatusString();
}
if(PS3.getButtonClick(START))
output += " - Start";
if (PS3.getButtonClick(START))
output += " - Start";
if(output != "") {
if (output != "") {
String string = "PS3 Controller" + output;
Serial.println(string);
if(SerialBT.connected)
if (SerialBT.connected)
SerialBT.println(string);
}
}

View file

@ -1,6 +1,6 @@
/*
Example sketch for the RFCOMM/SPP Bluetooth library - developed by Kristian Lauszus
For more information visit my blog: http://blog.tkjelectronics.dk/ or
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
*/
@ -21,23 +21,23 @@ void setup() {
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
while (1); //halt
}
Serial.print(F("\r\nSPP Bluetooth Library Started"));
}
void loop() {
Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well
if(SerialBT.connected) {
if(firstMessage) {
if (SerialBT.connected) {
if (firstMessage) {
firstMessage = false;
SerialBT.println(F("Hello from Arduino")); // Send welcome message
}
if(Serial.available())
if (Serial.available())
SerialBT.write(Serial.read());
if(SerialBT.available())
if (SerialBT.available())
Serial.write(SerialBT.read());
}
else
}
else
firstMessage = true;
}

View file

@ -1,6 +1,6 @@
/*
Example sketch for the RFCOMM/SPP Bluetooth library - developed by Kristian Lauszus
For more information visit my blog: http://blog.tkjelectronics.dk/ or
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
*/
@ -10,54 +10,54 @@
USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
SPP* SerialBT[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like, but it will use a lot of RAM!
const uint8_t length = sizeof(SerialBT)/sizeof(SerialBT[0]); // Get the lenght of the array
SPP *SerialBT[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like, but it will use a lot of RAM!
const uint8_t length = sizeof(SerialBT) / sizeof(SerialBT[0]); // Get the lenght of the array
boolean firstMessage[length] = { true }; // Set all to true
uint8_t buffer[50];
void setup() {
for(uint8_t i=0;i<length;i++)
for (uint8_t i = 0; i < length; i++)
SerialBT[i] = new SPP(&Btd); // This will set the name to the default: "Arduino" and the pin to "1234" for all connections
Serial.begin(115200);
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
while (1); //halt
}
Serial.print(F("\r\nSPP Bluetooth Library Started"));
}
void loop() {
Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well
for(uint8_t i=0;i<length;i++) {
if(SerialBT[i]->connected) {
if(firstMessage[i]) {
for (uint8_t i = 0; i < length; i++) {
if (SerialBT[i]->connected) {
if (firstMessage[i]) {
firstMessage[i] = false;
SerialBT[i]->println(F("Hello from Arduino")); // Send welcome message
}
if(SerialBT[i]->available())
if (SerialBT[i]->available())
Serial.write(SerialBT[i]->read());
}
}
else
firstMessage[i] = true;
}
if(Serial.available()) {
if (Serial.available()) {
delay(10); // Wait for the rest of the data to arrive
uint8_t i = 0;
while(Serial.available() && i < sizeof(buffer)) // Read the data
while (Serial.available() && i < sizeof(buffer)) // Read the data
buffer[i++] = Serial.read();
/*
/*
Set the connection you want to send to using the first character
For instace "0Hello World" would send "Hello World" to connection 0
For instace "0Hello World" would send "Hello World" to connection 0
*/
uint8_t id = buffer[0]-'0'; // Convert from ASCII
if(id < length && i > 1) { // And then compare to length and make sure there is any text
if(SerialBT[id]->connected) { // Check if a device is actually connected
for(uint8_t i2 = 0; i2 < i-1; i2++) // Don't include the first character
buffer[i2] = buffer[i2+1];
SerialBT[id]->write(buffer,i-1); // Send the data
uint8_t id = buffer[0] - '0'; // Convert from ASCII
if (id < length && i > 1) { // And then compare to length and make sure there is any text
if (SerialBT[id]->connected) { // Check if a device is actually connected
for (uint8_t i2 = 0; i2 < i - 1; i2++) // Don't include the first character
buffer[i2] = buffer[i2 + 1];
SerialBT[id]->write(buffer, i - 1); // Send the data
}
}
}
}
}

View file

@ -1,6 +1,6 @@
/*
Example sketch for the Wiimote Bluetooth library - developed by Kristian Lauszus
For more information visit my blog: http://blog.tkjelectronics.dk/ or
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
*/
@ -11,7 +11,7 @@ USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
WII Wii(&Btd,PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
//WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote
bool printAngle;
@ -21,68 +21,68 @@ void setup() {
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
while (1); //halt
}
Serial.print(F("\r\nWiimote Bluetooth Library Started"));
}
void loop() {
Usb.Task();
if(Wii.wiimoteConnected) {
if(Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
if (Wii.wiimoteConnected) {
if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
Serial.print(F("\r\nHOME"));
Wii.disconnect();
}
}
else {
if(Wii.getButtonClick(LEFT)) {
if (Wii.getButtonClick(LEFT)) {
Wii.setAllOff();
Wii.setLedOn(LED1);
Serial.print(F("\r\nLeft"));
}
if(Wii.getButtonClick(RIGHT)) {
if (Wii.getButtonClick(RIGHT)) {
Wii.setAllOff();
Wii.setLedOn(LED3);
Serial.print(F("\r\nRight"));
}
if(Wii.getButtonClick(DOWN)) {
if (Wii.getButtonClick(DOWN)) {
Wii.setAllOff();
Wii.setLedOn(LED4);
Serial.print(F("\r\nDown"));
}
if(Wii.getButtonClick(UP)) {
}
if (Wii.getButtonClick(UP)) {
Wii.setAllOff();
Wii.setLedOn(LED2);
Wii.setLedOn(LED2);
Serial.print(F("\r\nUp"));
}
if(Wii.getButtonClick(PLUS))
if (Wii.getButtonClick(PLUS))
Serial.print(F("\r\nPlus"));
if(Wii.getButtonClick(MINUS))
if (Wii.getButtonClick(MINUS))
Serial.print(F("\r\nMinus"));
if(Wii.getButtonClick(ONE))
if (Wii.getButtonClick(ONE))
Serial.print(F("\r\nOne"));
if(Wii.getButtonClick(TWO))
if (Wii.getButtonClick(TWO))
Serial.print(F("\r\nTwo"));
if(Wii.getButtonClick(A)) {
if (Wii.getButtonClick(A)) {
printAngle = !printAngle;
Serial.print(F("\r\nA"));
}
if(Wii.getButtonClick(B)) {
}
if (Wii.getButtonClick(B)) {
Wii.setRumbleToggle();
Serial.print(F("\r\nB"));
}
}
if(printAngle) {
if (printAngle) {
Serial.print(F("\r\nPitch: "));
Serial.print(Wii.getPitch());
Serial.print(F("\tRoll: "));
Serial.print(Wii.getRoll());
if(Wii.motionPlusConnected) {
if (Wii.motionPlusConnected) {
Serial.print(F("\tYaw: "));
Serial.print(Wii.getYaw());
}
if(Wii.nunchuckConnected) {
}
if (Wii.nunchuckConnected) {
Serial.print(F("\tNunchuck Pitch: "));
Serial.print(Wii.getNunchuckPitch());
Serial.print(F("\tNunchuck Roll: "));
@ -90,12 +90,12 @@ void loop() {
}
}
}
if(Wii.nunchuckConnected) {
if(Wii.getButtonClick(Z))
if (Wii.nunchuckConnected) {
if (Wii.getButtonClick(Z))
Serial.print(F("\r\nZ"));
if(Wii.getButtonClick(C))
if (Wii.getButtonClick(C))
Serial.print(F("\r\nC"));
if(Wii.getAnalogHat(HatX) > 137 || Wii.getAnalogHat(HatX) < 117 || Wii.getAnalogHat(HatY) > 137 || Wii.getAnalogHat(HatY) < 117) {
if (Wii.getAnalogHat(HatX) > 137 || Wii.getAnalogHat(HatX) < 117 || Wii.getAnalogHat(HatY) > 137 || Wii.getAnalogHat(HatY) < 117) {
Serial.print(F("\r\nHatX: "));
Serial.print(Wii.getAnalogHat(HatX));
Serial.print(F("\tHatY: "));

View file

@ -1,12 +1,12 @@
/*
Example sketch for the Wii libary showing the IR camera functionality. This example
is for the Bluetooth Wii library developed for the USB shield from Circuits@Home
Created by Allan Glover and Kristian Lauszus.
Contact Kristian: http://blog.tkjelectronics.dk/ or send an email at kristianl@tkjelectronics.com.
Contact Allan at adglover9.81@gmail.com
To test the Wiimote IR camera, you will need access to an IR source. Sunlight will work but is not ideal.
To test the Wiimote IR camera, you will need access to an IR source. Sunlight will work but is not ideal.
The simpleist solution is to use the Wii sensor bar, i.e. emitter bar, supplied by the Wii system.
Otherwise, wire up a IR LED yourself.
*/
@ -22,7 +22,7 @@ USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
WII Wii(&Btd,PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
//WII Wii(&Btd); // After the Wiimote pairs once with the line of code above, you can simply create the instance like so and re upload and then press any button on the Wiimote
bool printAngle;
@ -33,31 +33,31 @@ void setup() {
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
while (1); //halt
}
Serial.print(F("\r\nWiimote Bluetooth Library Started"));
}
void loop() {
Usb.Task();
if(Wii.wiimoteConnected) {
if(Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
if (Wii.wiimoteConnected) {
if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
Serial.print(F("\r\nHOME"));
Wii.disconnect();
}
else {
if(Wii.getButtonClick(ONE))
if (Wii.getButtonClick(ONE))
Wii.IRinitialize(); // Run the initialisation sequence
if(Wii.getButtonClick(MINUS) || Wii.getButtonClick(PLUS)) {
if(!Wii.isIRCameraEnabled())
if (Wii.getButtonClick(MINUS) || Wii.getButtonClick(PLUS)) {
if (!Wii.isIRCameraEnabled())
Serial.print(F("\r\nEnable IR camera first"));
else {
if(Wii.getButtonPress(MINUS)) { // getButtonClick will only return true once
if(printObjects > 0)
printObjects--;
if (Wii.getButtonPress(MINUS)) { // getButtonClick will only return true once
if (printObjects > 0)
printObjects--;
}
else {
if(printObjects < 4)
if (printObjects < 4)
printObjects++;
}
Serial.print(F("\r\nTracking "));
@ -65,56 +65,56 @@ void loop() {
Serial.print(F(" objects"));
}
}
if(Wii.getButtonClick(A)) {
if (Wii.getButtonClick(A)) {
printAngle = !printAngle;
Serial.print(F("\r\nA"));
}
if(Wii.getButtonClick(B)) {
if (Wii.getButtonClick(B)) {
Serial.print(F("\r\nBattery level: "));
Serial.print(Wii.getBatteryLevel()); // You can get the battery level as well
}
}
if(printObjects > 0) {
if(Wii.getIRx1() != 0x3FF || Wii.getIRy1() != 0x3FF || Wii.getIRs1() != 0) { // Only print if the IR camera is actually seeing something
if (printObjects > 0) {
if (Wii.getIRx1() != 0x3FF || Wii.getIRy1() != 0x3FF || Wii.getIRs1() != 0) { // Only print if the IR camera is actually seeing something
Serial.print(F("\r\nx1: "));
Serial.print(Wii.getIRx1());
Serial.print(Wii.getIRx1());
Serial.print(F("\ty1: "));
Serial.print(Wii.getIRy1());
Serial.print(Wii.getIRy1());
Serial.print(F("\ts1:"));
Serial.print(Wii.getIRs1());
}
if(printObjects > 1) {
if(Wii.getIRx2() != 0x3FF || Wii.getIRy2() != 0x3FF || Wii.getIRs2() != 0) {
if (printObjects > 1) {
if (Wii.getIRx2() != 0x3FF || Wii.getIRy2() != 0x3FF || Wii.getIRs2() != 0) {
Serial.print(F("\r\nx2: "));
Serial.print(Wii.getIRx2());
Serial.print(Wii.getIRx2());
Serial.print(F("\ty2: "));
Serial.print(Wii.getIRy2());
Serial.print(Wii.getIRy2());
Serial.print(F("\ts2:"));
Serial.print(Wii.getIRs2());
}
if(printObjects > 2) {
if(Wii.getIRx3() != 0x3FF || Wii.getIRy3() != 0x3FF || Wii.getIRs3() != 0) {
if (printObjects > 2) {
if (Wii.getIRx3() != 0x3FF || Wii.getIRy3() != 0x3FF || Wii.getIRs3() != 0) {
Serial.print(F("\r\nx3: "));
Serial.print(Wii.getIRx3());
Serial.print(Wii.getIRx3());
Serial.print(F("\ty3: "));
Serial.print(Wii.getIRy3());
Serial.print(Wii.getIRy3());
Serial.print(F("\ts3:"));
Serial.print(Wii.getIRs3());
}
if(printObjects > 3) {
if(Wii.getIRx4() != 0x3FF || Wii.getIRy4() != 0x3FF || Wii.getIRs4() != 0) {
if (printObjects > 3) {
if (Wii.getIRx4() != 0x3FF || Wii.getIRy4() != 0x3FF || Wii.getIRs4() != 0) {
Serial.print(F("\r\nx4: "));
Serial.print(Wii.getIRx4());
Serial.print(Wii.getIRx4());
Serial.print(F("\ty4: "));
Serial.print(Wii.getIRy4());
Serial.print(Wii.getIRy4());
Serial.print(F("\ts4:"));
Serial.print(Wii.getIRs4());
}
}
}
}
}
if(printAngle) { // There is no extension bytes available, so the MotionPlus or Nunchuck can't be read
}
if (printAngle) { // There is no extension bytes available, so the MotionPlus or Nunchuck can't be read
Serial.print(F("\r\nPitch: "));
Serial.print(Wii.getPitch());
Serial.print(F("\tRoll: "));

View file

@ -1,7 +1,7 @@
/*
Example sketch for the Wiimote Bluetooth library - developed by Kristian Lauszus
This example show how one can use multiple controllers with the library
For more information visit my blog: http://blog.tkjelectronics.dk/ or
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
*/
@ -12,85 +12,85 @@ USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
WII *Wii[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like, but it will use a lot of RAM!
const uint8_t length = sizeof(Wii)/sizeof(Wii[0]); // Get the lenght of the array
const uint8_t length = sizeof(Wii) / sizeof(Wii[0]); // Get the lenght of the array
boolean printAngle[length];
boolean oldControllerState[length];
void setup() {
for (uint8_t i=0;i<length;i++) {
for (uint8_t i = 0; i < length; i++) {
Wii[i] = new WII(&Btd); // You will have to pair each controller with the dongle before you can define the instances like so, just add PAIR as the second argument
Wii[i]->attachOnInit(onInit); // onInit() is called upon a new connection - you can call the function whatever you like
}
Serial.begin(115200);
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
while (1); //halt
}
Serial.print(F("\r\nWiimote Bluetooth Library Started"));
}
void loop() {
Usb.Task();
for(uint8_t i=0;i<length;i++) {
if(Wii[i]->wiimoteConnected) {
if(Wii[i]->getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
for (uint8_t i = 0; i < length; i++) {
if (Wii[i]->wiimoteConnected) {
if (Wii[i]->getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
Serial.print(F("\r\nHOME"));
Wii[i]->disconnect();
oldControllerState[i] = false; // Reset value
}
}
else {
if(Wii[i]->getButtonClick(LEFT)) {
if (Wii[i]->getButtonClick(LEFT)) {
Wii[i]->setAllOff();
Wii[i]->setLedOn(LED1);
Serial.print(F("\r\nLeft"));
}
if(Wii[i]->getButtonClick(RIGHT)) {
if (Wii[i]->getButtonClick(RIGHT)) {
Wii[i]->setAllOff();
Wii[i]->setLedOn(LED3);
Serial.print(F("\r\nRight"));
}
if(Wii[i]->getButtonClick(DOWN)) {
if (Wii[i]->getButtonClick(DOWN)) {
Wii[i]->setAllOff();
Wii[i]->setLedOn(LED4);
Serial.print(F("\r\nDown"));
}
if(Wii[i]->getButtonClick(UP)) {
}
if (Wii[i]->getButtonClick(UP)) {
Wii[i]->setAllOff();
Wii[i]->setLedOn(LED2);
Wii[i]->setLedOn(LED2);
Serial.print(F("\r\nUp"));
}
if(Wii[i]->getButtonClick(PLUS))
if (Wii[i]->getButtonClick(PLUS))
Serial.print(F("\r\nPlus"));
if(Wii[i]->getButtonClick(MINUS))
if (Wii[i]->getButtonClick(MINUS))
Serial.print(F("\r\nMinus"));
if(Wii[i]->getButtonClick(ONE))
if (Wii[i]->getButtonClick(ONE))
Serial.print(F("\r\nOne"));
if(Wii[i]->getButtonClick(TWO))
if (Wii[i]->getButtonClick(TWO))
Serial.print(F("\r\nTwo"));
if(Wii[i]->getButtonClick(A)) {
if (Wii[i]->getButtonClick(A)) {
printAngle[i] = !printAngle[i];
Serial.print(F("\r\nA"));
}
if(Wii[i]->getButtonClick(B)) {
}
if (Wii[i]->getButtonClick(B)) {
Wii[i]->setRumbleToggle();
Serial.print(F("\r\nB"));
}
}
if(printAngle[i]) {
if (printAngle[i]) {
Serial.print(F("\r\nPitch: "));
Serial.print(Wii[i]->getPitch());
Serial.print(F("\tRoll: "));
Serial.print(Wii[i]->getRoll());
if(Wii[i]->motionPlusConnected) {
if (Wii[i]->motionPlusConnected) {
Serial.print(F("\tYaw: "));
Serial.print(Wii[i]->getYaw());
}
if(Wii[i]->nunchuckConnected) {
}
if (Wii[i]->nunchuckConnected) {
Serial.print(F("\tNunchuck Pitch: "));
Serial.print(Wii[i]->getNunchuckPitch());
Serial.print(F("\tNunchuck Roll: "));
@ -98,12 +98,12 @@ void loop() {
}
}
}
if(Wii[i]->nunchuckConnected) {
if(Wii[i]->getButtonClick(Z))
if (Wii[i]->nunchuckConnected) {
if (Wii[i]->getButtonClick(Z))
Serial.print(F("\r\nZ"));
if(Wii[i]->getButtonClick(C))
if (Wii[i]->getButtonClick(C))
Serial.print(F("\r\nC"));
if(Wii[i]->getAnalogHat(HatX) > 137 || Wii[i]->getAnalogHat(HatX) < 117 || Wii[i]->getAnalogHat(HatY) > 137 || Wii[i]->getAnalogHat(HatY) < 117) {
if (Wii[i]->getAnalogHat(HatX) > 137 || Wii[i]->getAnalogHat(HatX) < 117 || Wii[i]->getAnalogHat(HatY) > 137 || Wii[i]->getAnalogHat(HatY) < 117) {
Serial.print(F("\r\nHatX: "));
Serial.print(Wii[i]->getAnalogHat(HatX));
Serial.print(F("\tHatY: "));
@ -114,7 +114,7 @@ void loop() {
}
void onInit() {
for (uint8_t i=0;i<length;i++) {
for (uint8_t i = 0; i < length; i++) {
if (Wii[i]->wiimoteConnected && !oldControllerState[i]) {
oldControllerState[i] = true; // Used to check which is the new controller
Wii[i]->setLedOn((LED)i); // Cast directly to LED enum - see: "controllerEnums.h"

View file

@ -1,6 +1,6 @@
/*
Example sketch for the Wiimote Bluetooth library - developed by Kristian Lauszus
For more information visit my blog: http://blog.tkjelectronics.dk/ or
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
*/
@ -11,7 +11,7 @@ USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
WII Wii(&Btd,PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
//WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote
void setup() {
@ -19,69 +19,69 @@ void setup() {
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
while (1); //halt
}
Serial.print(F("\r\nWiimote Bluetooth Library Started"));
}
void loop() {
Usb.Task();
if(Wii.wiiUProControllerConnected) {
if(Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
if (Wii.wiiUProControllerConnected) {
if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
Serial.print(F("\r\nHome"));
Wii.disconnect();
}
}
else {
if(Wii.getButtonClick(LEFT)) {
if (Wii.getButtonClick(LEFT)) {
Wii.setAllOff();
Wii.setLedOn(LED1);
Serial.print(F("\r\nLeft"));
}
if(Wii.getButtonClick(RIGHT)) {
if (Wii.getButtonClick(RIGHT)) {
Wii.setAllOff();
Wii.setLedOn(LED3);
Serial.print(F("\r\nRight"));
}
if(Wii.getButtonClick(DOWN)) {
if (Wii.getButtonClick(DOWN)) {
Wii.setAllOff();
Wii.setLedOn(LED4);
Serial.print(F("\r\nDown"));
}
if(Wii.getButtonClick(UP)) {
}
if (Wii.getButtonClick(UP)) {
Wii.setAllOff();
Wii.setLedOn(LED2);
Wii.setLedOn(LED2);
Serial.print(F("\r\nUp"));
}
if(Wii.getButtonClick(PLUS))
if (Wii.getButtonClick(PLUS))
Serial.print(F("\r\nPlus"));
if(Wii.getButtonClick(MINUS))
if (Wii.getButtonClick(MINUS))
Serial.print(F("\r\nMinus"));
if(Wii.getButtonClick(A))
if (Wii.getButtonClick(A))
Serial.print(F("\r\nA"));
if(Wii.getButtonClick(B)) {
if (Wii.getButtonClick(B)) {
Wii.setRumbleToggle();
Serial.print(F("\r\nB"));
}
if(Wii.getButtonClick(X))
if (Wii.getButtonClick(X))
Serial.print(F("\r\nX"));
if(Wii.getButtonClick(Y))
if (Wii.getButtonClick(Y))
Serial.print(F("\r\nY"));
if(Wii.getButtonClick(L))
if (Wii.getButtonClick(L))
Serial.print(F("\r\nL"));
if(Wii.getButtonClick(R))
if (Wii.getButtonClick(R))
Serial.print(F("\r\nR"));
if(Wii.getButtonClick(ZL))
if (Wii.getButtonClick(ZL))
Serial.print(F("\r\nZL"));
if(Wii.getButtonClick(ZR))
if (Wii.getButtonClick(ZR))
Serial.print(F("\r\nZR"));
if(Wii.getButtonClick(L3))
if (Wii.getButtonClick(L3))
Serial.print(F("\r\nL3"));
if(Wii.getButtonClick(R3))
Serial.print(F("\r\nR3"));
if (Wii.getButtonClick(R3))
Serial.print(F("\r\nR3"));
}
if(Wii.getAnalogHat(LeftHatX) > 2200 || Wii.getAnalogHat(LeftHatX) < 1800 || Wii.getAnalogHat(LeftHatY) > 2200 || Wii.getAnalogHat(LeftHatY) < 1800 || Wii.getAnalogHat(RightHatX) > 2200 || Wii.getAnalogHat(RightHatX) < 1800 || Wii.getAnalogHat(RightHatY) > 2200 || Wii.getAnalogHat(RightHatY) < 1800) {
if (Wii.getAnalogHat(LeftHatX) > 2200 || Wii.getAnalogHat(LeftHatX) < 1800 || Wii.getAnalogHat(LeftHatY) > 2200 || Wii.getAnalogHat(LeftHatY) < 1800 || Wii.getAnalogHat(RightHatX) > 2200 || Wii.getAnalogHat(RightHatX) < 1800 || Wii.getAnalogHat(RightHatY) > 2200 || Wii.getAnalogHat(RightHatY) < 1800) {
Serial.print(F("\r\nLeftHatX: "));
Serial.print(Wii.getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: "));

View file

@ -1,6 +1,6 @@
/*
Example sketch for the original Xbox library - developed by Kristian Lauszus
For more information visit my blog: http://blog.tkjelectronics.dk/ or
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
*/
@ -16,83 +16,83 @@ void setup() {
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
}
while (1); // halt
}
Serial.print(F("\r\nXBOX Library Started"));
}
void loop() {
Usb.Task();
if(Xbox.XboxConnected) {
if(Xbox.getButtonPress(BLACK) || Xbox.getButtonPress(WHITE)) {
if (Xbox.XboxConnected) {
if (Xbox.getButtonPress(BLACK) || Xbox.getButtonPress(WHITE)) {
Serial.print("BLACK: ");
Serial.print(Xbox.getButtonPress(BLACK));
Serial.print("\tWHITE: ");
Serial.println(Xbox.getButtonPress(WHITE));
Xbox.setRumbleOn(Xbox.getButtonPress(BLACK),Xbox.getButtonPress(WHITE));
Xbox.setRumbleOn(Xbox.getButtonPress(BLACK), Xbox.getButtonPress(WHITE));
} else
Xbox.setRumbleOn(0,0);
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: "));
Xbox.setRumbleOn(0, 0);
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: "));
Serial.print(Xbox.getAnalogHat(LeftHatX));
Serial.print("\t");
}
if(Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) {
Serial.print(F("LeftHatY: "));
}
if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) {
Serial.print(F("LeftHatY: "));
Serial.print(Xbox.getAnalogHat(LeftHatY));
Serial.print("\t");
}
if(Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) {
Serial.print(F("RightHatX: "));
}
if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) {
Serial.print(F("RightHatX: "));
Serial.print(Xbox.getAnalogHat(RightHatX));
Serial.print("\t");
}
if(Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) {
Serial.print(F("RightHatY: "));
Serial.print(Xbox.getAnalogHat(RightHatY));
Serial.print("\t");
}
if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) {
Serial.print(F("RightHatY: "));
Serial.print(Xbox.getAnalogHat(RightHatY));
}
Serial.println();
}
if(Xbox.getButtonClick(UP))
if (Xbox.getButtonClick(UP))
Serial.println(F("Up"));
if(Xbox.getButtonClick(DOWN))
if (Xbox.getButtonClick(DOWN))
Serial.println(F("Down"));
if(Xbox.getButtonClick(LEFT))
if (Xbox.getButtonClick(LEFT))
Serial.println(F("Left"));
if(Xbox.getButtonClick(RIGHT))
if (Xbox.getButtonClick(RIGHT))
Serial.println(F("Right"));
if(Xbox.getButtonClick(START))
if (Xbox.getButtonClick(START))
Serial.println(F("Start"));
if(Xbox.getButtonClick(BACK))
if (Xbox.getButtonClick(BACK))
Serial.println(F("Back"));
if(Xbox.getButtonClick(L3))
if (Xbox.getButtonClick(L3))
Serial.println(F("L3"));
if(Xbox.getButtonClick(R3))
if (Xbox.getButtonClick(R3))
Serial.println(F("R3"));
if(Xbox.getButtonPress(A)) {
if (Xbox.getButtonPress(A)) {
Serial.print(F("A: "));
Serial.println(Xbox.getButtonPress(A));
}
if(Xbox.getButtonPress(B)) {
if (Xbox.getButtonPress(B)) {
Serial.print(F("B: "));
Serial.println(Xbox.getButtonPress(B));
}
if(Xbox.getButtonPress(X)) {
if (Xbox.getButtonPress(X)) {
Serial.print(F("X: "));
Serial.println(Xbox.getButtonPress(X));
}
if(Xbox.getButtonPress(Y)) {
if (Xbox.getButtonPress(Y)) {
Serial.print(F("Y: "));
Serial.println(Xbox.getButtonPress(Y));
}
if(Xbox.getButtonPress(L1)) {
if (Xbox.getButtonPress(L1)) {
Serial.print(F("L1: "));
Serial.println(Xbox.getButtonPress(L1));
}
if(Xbox.getButtonPress(R1)) {
if (Xbox.getButtonPress(R1)) {
Serial.print(F("R1: "));
Serial.println(Xbox.getButtonPress(R1));
}

View file

@ -1,6 +1,6 @@
/*
Example sketch for the Xbox 360 USB library - developed by Kristian Lauszus
For more information visit my blog: http://blog.tkjelectronics.dk/ or
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
*/
@ -14,90 +14,90 @@ void setup() {
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
}
while (1); //halt
}
Serial.print(F("\r\nXBOX USB Library Started"));
}
void loop() {
Usb.Task();
if(Xbox.Xbox360Connected) {
if(Xbox.getButtonPress(L2) || Xbox.getButtonPress(R2)) {
if (Xbox.Xbox360Connected) {
if (Xbox.getButtonPress(L2) || Xbox.getButtonPress(R2)) {
Serial.print("L2: ");
Serial.print(Xbox.getButtonPress(L2));
Serial.print("\tR2: ");
Serial.println(Xbox.getButtonPress(R2));
Xbox.setRumbleOn(Xbox.getButtonPress(L2),Xbox.getButtonPress(R2));
Xbox.setRumbleOn(Xbox.getButtonPress(L2), Xbox.getButtonPress(R2));
} else
Xbox.setRumbleOn(0,0);
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: "));
Xbox.setRumbleOn(0, 0);
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: "));
Serial.print(Xbox.getAnalogHat(LeftHatX));
Serial.print("\t");
}
if(Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) {
Serial.print(F("LeftHatY: "));
}
if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) {
Serial.print(F("LeftHatY: "));
Serial.print(Xbox.getAnalogHat(LeftHatY));
Serial.print("\t");
}
if(Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) {
Serial.print(F("RightHatX: "));
}
if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) {
Serial.print(F("RightHatX: "));
Serial.print(Xbox.getAnalogHat(RightHatX));
Serial.print("\t");
}
if(Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) {
Serial.print(F("RightHatY: "));
Serial.print(Xbox.getAnalogHat(RightHatY));
Serial.print("\t");
}
if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) {
Serial.print(F("RightHatY: "));
Serial.print(Xbox.getAnalogHat(RightHatY));
}
Serial.println();
}
if(Xbox.getButtonClick(UP)) {
if (Xbox.getButtonClick(UP)) {
Xbox.setLedOn(LED1);
Serial.println(F("Up"));
}
if(Xbox.getButtonClick(DOWN)) {
}
if (Xbox.getButtonClick(DOWN)) {
Xbox.setLedOn(LED4);
Serial.println(F("Down"));
}
if(Xbox.getButtonClick(LEFT)) {
if (Xbox.getButtonClick(LEFT)) {
Xbox.setLedOn(LED3);
Serial.println(F("Left"));
}
if(Xbox.getButtonClick(RIGHT)) {
if (Xbox.getButtonClick(RIGHT)) {
Xbox.setLedOn(LED2);
Serial.println(F("Right"));
}
if(Xbox.getButtonClick(START)) {
if (Xbox.getButtonClick(START)) {
Xbox.setLedMode(ALTERNATING);
Serial.println(F("Start"));
}
if(Xbox.getButtonClick(BACK)) {
if (Xbox.getButtonClick(BACK)) {
Xbox.setLedBlink(ALL);
Serial.println(F("Back"));
}
if(Xbox.getButtonClick(L3))
if (Xbox.getButtonClick(L3))
Serial.println(F("L3"));
if(Xbox.getButtonClick(R3))
if (Xbox.getButtonClick(R3))
Serial.println(F("R3"));
if(Xbox.getButtonClick(L1))
if (Xbox.getButtonClick(L1))
Serial.println(F("L1"));
if(Xbox.getButtonClick(R1))
if (Xbox.getButtonClick(R1))
Serial.println(F("R1"));
if(Xbox.getButtonClick(XBOX)) {
if (Xbox.getButtonClick(XBOX)) {
Xbox.setLedMode(ROTATING);
Serial.println(F("Xbox"));
Serial.println(F("Xbox"));
}
if(Xbox.getButtonClick(A))
if (Xbox.getButtonClick(A))
Serial.println(F("A"));
if(Xbox.getButtonClick(B))
if (Xbox.getButtonClick(B))
Serial.println(F("B"));
if(Xbox.getButtonClick(X))
if (Xbox.getButtonClick(X))
Serial.println(F("X"));
if(Xbox.getButtonClick(Y))
if (Xbox.getButtonClick(Y))
Serial.println(F("Y"));
}
delay(1);