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

@ -12,12 +12,12 @@ USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 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! 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 printAngle[length];
boolean oldControllerState[length]; boolean oldControllerState[length];
void setup() { 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] = 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 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 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) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); //halt while (1); //halt
} }
Serial.print(F("\r\nPS3 Bluetooth Library Started")); Serial.print(F("\r\nPS3 Bluetooth Library Started"));
} }
void loop() { void loop() {
Usb.Task(); Usb.Task();
for(uint8_t i=0;i<length;i++) { for (uint8_t i = 0; i < length; i++) {
if(PS3[i]->PS3Connected || PS3[i]->PS3NavigationConnected) { 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) { 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(F("\r\nLeftHatX: "));
Serial.print(PS3[i]->getAnalogHat(LeftHatX)); Serial.print(PS3[i]->getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: ")); Serial.print(F("\tLeftHatY: "));
Serial.print(PS3[i]->getAnalogHat(LeftHatY)); 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(F("\tRightHatX: "));
Serial.print(PS3[i]->getAnalogHat(RightHatX)); Serial.print(PS3[i]->getAnalogHat(RightHatX));
Serial.print(F("\tRightHatY: ")); Serial.print(F("\tRightHatY: "));
@ -48,77 +48,77 @@ void loop() {
} }
} }
//Analog button values can be read from almost all buttons //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(F("\r\nL2: "));
Serial.print(PS3[i]->getAnalogButton(L2)); Serial.print(PS3[i]->getAnalogButton(L2));
if(!PS3[i]->PS3NavigationConnected) { if (!PS3[i]->PS3NavigationConnected) {
Serial.print(F("\tR2: ")); Serial.print(F("\tR2: "));
Serial.print(PS3[i]->getAnalogButton(R2)); Serial.print(PS3[i]->getAnalogButton(R2));
} }
} }
if(PS3[i]->getButtonClick(PS)) { if (PS3[i]->getButtonClick(PS)) {
Serial.print(F("\r\nPS")); Serial.print(F("\r\nPS"));
PS3[i]->disconnect(); PS3[i]->disconnect();
oldControllerState[i] = false; // Reset value oldControllerState[i] = false; // Reset value
} }
else { else {
if(PS3[i]->getButtonClick(TRIANGLE)) if (PS3[i]->getButtonClick(TRIANGLE))
Serial.print(F("\r\nTraingle")); Serial.print(F("\r\nTraingle"));
if(PS3[i]->getButtonClick(CIRCLE)) if (PS3[i]->getButtonClick(CIRCLE))
Serial.print(F("\r\nCircle")); Serial.print(F("\r\nCircle"));
if(PS3[i]->getButtonClick(CROSS)) if (PS3[i]->getButtonClick(CROSS))
Serial.print(F("\r\nCross")); Serial.print(F("\r\nCross"));
if(PS3[i]->getButtonClick(SQUARE)) if (PS3[i]->getButtonClick(SQUARE))
Serial.print(F("\r\nSquare")); Serial.print(F("\r\nSquare"));
if(PS3[i]->getButtonClick(UP)) { if (PS3[i]->getButtonClick(UP)) {
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
if(PS3[i]->PS3Connected) { if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff(); PS3[i]->setAllOff();
PS3[i]->setLedOn(LED4); PS3[i]->setLedOn(LED4);
} }
} }
if(PS3[i]->getButtonClick(RIGHT)) { if (PS3[i]->getButtonClick(RIGHT)) {
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
if(PS3[i]->PS3Connected) { if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff(); PS3[i]->setAllOff();
PS3[i]->setLedOn(LED1); PS3[i]->setLedOn(LED1);
} }
} }
if(PS3[i]->getButtonClick(DOWN)) { if (PS3[i]->getButtonClick(DOWN)) {
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
if(PS3[i]->PS3Connected) { if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff(); PS3[i]->setAllOff();
PS3[i]->setLedOn(LED2); PS3[i]->setLedOn(LED2);
} }
} }
if(PS3[i]->getButtonClick(LEFT)) { if (PS3[i]->getButtonClick(LEFT)) {
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
if(PS3[i]->PS3Connected) { if (PS3[i]->PS3Connected) {
PS3[i]->setAllOff(); PS3[i]->setAllOff();
PS3[i]->setLedOn(LED3); PS3[i]->setLedOn(LED3);
} }
} }
if(PS3[i]->getButtonClick(L1)) if (PS3[i]->getButtonClick(L1))
Serial.print(F("\r\nL1")); Serial.print(F("\r\nL1"));
if(PS3[i]->getButtonClick(L3)) if (PS3[i]->getButtonClick(L3))
Serial.print(F("\r\nL3")); Serial.print(F("\r\nL3"));
if(PS3[i]->getButtonClick(R1)) if (PS3[i]->getButtonClick(R1))
Serial.print(F("\r\nR1")); Serial.print(F("\r\nR1"));
if(PS3[i]->getButtonClick(R3)) if (PS3[i]->getButtonClick(R3))
Serial.print(F("\r\nR3")); Serial.print(F("\r\nR3"));
if(PS3[i]->getButtonClick(SELECT)) { if (PS3[i]->getButtonClick(SELECT)) {
Serial.print(F("\r\nSelect - ")); Serial.print(F("\r\nSelect - "));
Serial.print(PS3[i]->getStatusString()); Serial.print(PS3[i]->getStatusString());
} }
if(PS3[i]->getButtonClick(START)) { if (PS3[i]->getButtonClick(START)) {
Serial.print(F("\r\nStart")); Serial.print(F("\r\nStart"));
printAngle[i] = !printAngle[i]; printAngle[i] = !printAngle[i];
} }
} }
if(printAngle[i]) { if (printAngle[i]) {
Serial.print(F("\r\nPitch: ")); Serial.print(F("\r\nPitch: "));
Serial.print(PS3[i]->getAngle(Pitch)); Serial.print(PS3[i]->getAngle(Pitch));
Serial.print(F("\tRoll: ")); Serial.print(F("\tRoll: "));
@ -131,7 +131,7 @@ void loop() {
} }
void onInit() { 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]) { if ((PS3[i]->PS3Connected || PS3[i]->PS3NavigationConnected) && !oldControllerState[i]) {
oldControllerState[i] = true; // Used to check which is the new controller oldControllerState[i] = true; // Used to check which is the new controller
PS3[i]->setLedOn((LED)i); // Cast directly to LED enum - see: "controllerEnums.h" PS3[i]->setLedOn((LED)i); // Cast directly to LED enum - see: "controllerEnums.h"

View file

@ -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 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) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); //halt while (1); //halt
} }
Serial.print(F("\r\nBluetooth Library Started")); Serial.print(F("\r\nBluetooth Library Started"));
output.reserve(200); // Reserve 200 bytes for the output string output.reserve(200); // Reserve 200 bytes for the output string
@ -39,27 +39,27 @@ void setup() {
void loop() { void loop() {
Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well 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 (SerialBT.connected) {
if(firstMessage) { if (firstMessage) {
firstMessage = false; firstMessage = false;
SerialBT.println(F("Hello from Arduino")); // Send welcome message SerialBT.println(F("Hello from Arduino")); // Send welcome message
} }
if(Serial.available()) if (Serial.available())
SerialBT.write(Serial.read()); SerialBT.write(Serial.read());
if(SerialBT.available()) if (SerialBT.available())
Serial.write(SerialBT.read()); Serial.write(SerialBT.read());
} }
else else
firstMessage = true; firstMessage = true;
if(PS3.PS3Connected || PS3.PS3NavigationConnected) { if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
output = ""; // Reset output string 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 += "LeftHatX: ";
output += PS3.getAnalogHat(LeftHatX); output += PS3.getAnalogHat(LeftHatX);
output += "\tLeftHatY: "; output += "\tLeftHatY: ";
output += PS3.getAnalogHat(LeftHatY); output += PS3.getAnalogHat(LeftHatY);
if(!PS3.PS3NavigationConnected) { if (!PS3.PS3NavigationConnected) {
output += "\tRightHatX: "; output += "\tRightHatX: ";
output += PS3.getAnalogHat(RightHatX); output += PS3.getAnalogHat(RightHatX);
output += "\tRightHatY: "; output += "\tRightHatY: ";
@ -67,85 +67,85 @@ void loop() {
} }
} }
//Analog button values can be read from almost all buttons //Analog button values can be read from almost all buttons
if(PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) { if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
if(output != "") if (output != "")
output += "\r\n"; output += "\r\n";
output += "L2: "; output += "L2: ";
output += PS3.getAnalogButton(L2); output += PS3.getAnalogButton(L2);
if(!PS3.PS3NavigationConnected) { if (!PS3.PS3NavigationConnected) {
output += "\tR2: "; output += "\tR2: ";
output += PS3.getAnalogButton(R2); output += PS3.getAnalogButton(R2);
} }
} }
if(output != "") { if (output != "") {
Serial.println(output); Serial.println(output);
if(SerialBT.connected) if (SerialBT.connected)
SerialBT.println(output); SerialBT.println(output);
output = ""; // Reset output string output = ""; // Reset output string
} }
if(PS3.getButtonClick(PS)) { if (PS3.getButtonClick(PS)) {
output += " - PS"; output += " - PS";
PS3.disconnect(); PS3.disconnect();
} }
else { else {
if(PS3.getButtonClick(TRIANGLE)) if (PS3.getButtonClick(TRIANGLE))
output += " - Traingle"; output += " - Traingle";
if(PS3.getButtonClick(CIRCLE)) if (PS3.getButtonClick(CIRCLE))
output += " - Circle"; output += " - Circle";
if(PS3.getButtonClick(CROSS)) if (PS3.getButtonClick(CROSS))
output += " - Cross"; output += " - Cross";
if(PS3.getButtonClick(SQUARE)) if (PS3.getButtonClick(SQUARE))
output += " - Square"; output += " - Square";
if(PS3.getButtonClick(UP)) { if (PS3.getButtonClick(UP)) {
output += " - Up"; output += " - Up";
if(PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED4); PS3.setLedOn(LED4);
} }
} }
if(PS3.getButtonClick(RIGHT)) { if (PS3.getButtonClick(RIGHT)) {
output += " - Right"; output += " - Right";
if(PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED1); PS3.setLedOn(LED1);
} }
} }
if(PS3.getButtonClick(DOWN)) { if (PS3.getButtonClick(DOWN)) {
output += " - Down"; output += " - Down";
if(PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED2); PS3.setLedOn(LED2);
} }
} }
if(PS3.getButtonClick(LEFT)) { if (PS3.getButtonClick(LEFT)) {
output += " - Left"; output += " - Left";
if(PS3.PS3Connected) { if (PS3.PS3Connected) {
PS3.setAllOff(); PS3.setAllOff();
PS3.setLedOn(LED3); PS3.setLedOn(LED3);
} }
} }
if(PS3.getButtonClick(L1)) if (PS3.getButtonClick(L1))
output += " - L1"; output += " - L1";
if(PS3.getButtonClick(L3)) if (PS3.getButtonClick(L3))
output += " - L3"; output += " - L3";
if(PS3.getButtonClick(R1)) if (PS3.getButtonClick(R1))
output += " - R1"; output += " - R1";
if(PS3.getButtonClick(R3)) if (PS3.getButtonClick(R3))
output += " - R3"; output += " - R3";
if(PS3.getButtonClick(SELECT)) { if (PS3.getButtonClick(SELECT)) {
output += " - Select - "; output += " - Select - ";
output += PS3.getStatusString(); output += PS3.getStatusString();
} }
if(PS3.getButtonClick(START)) if (PS3.getButtonClick(START))
output += " - Start"; output += " - Start";
if(output != "") { if (output != "") {
String string = "PS3 Controller" + output; String string = "PS3 Controller" + output;
Serial.println(string); Serial.println(string);
if(SerialBT.connected) if (SerialBT.connected)
SerialBT.println(string); SerialBT.println(string);
} }
} }

View file

@ -21,21 +21,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 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) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); //halt while (1); //halt
} }
Serial.print(F("\r\nSPP Bluetooth Library Started")); Serial.print(F("\r\nSPP Bluetooth Library Started"));
} }
void loop() { void loop() {
Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well 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 (SerialBT.connected) {
if(firstMessage) { if (firstMessage) {
firstMessage = false; firstMessage = false;
SerialBT.println(F("Hello from Arduino")); // Send welcome message SerialBT.println(F("Hello from Arduino")); // Send welcome message
} }
if(Serial.available()) if (Serial.available())
SerialBT.write(Serial.read()); SerialBT.write(Serial.read());
if(SerialBT.available()) if (SerialBT.available())
Serial.write(SerialBT.read()); Serial.write(SerialBT.read());
} }
else else

View file

@ -10,53 +10,53 @@
USB Usb; USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 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! 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 const uint8_t length = sizeof(SerialBT) / sizeof(SerialBT[0]); // Get the lenght of the array
boolean firstMessage[length] = { true }; // Set all to true boolean firstMessage[length] = { true }; // Set all to true
uint8_t buffer[50]; uint8_t buffer[50];
void setup() { 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 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); 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 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) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); //halt while (1); //halt
} }
Serial.print(F("\r\nSPP Bluetooth Library Started")); Serial.print(F("\r\nSPP Bluetooth Library Started"));
} }
void loop() { void loop() {
Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well 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++) { for (uint8_t i = 0; i < length; i++) {
if(SerialBT[i]->connected) { if (SerialBT[i]->connected) {
if(firstMessage[i]) { if (firstMessage[i]) {
firstMessage[i] = false; firstMessage[i] = false;
SerialBT[i]->println(F("Hello from Arduino")); // Send welcome message SerialBT[i]->println(F("Hello from Arduino")); // Send welcome message
} }
if(SerialBT[i]->available()) if (SerialBT[i]->available())
Serial.write(SerialBT[i]->read()); Serial.write(SerialBT[i]->read());
} }
else else
firstMessage[i] = true; firstMessage[i] = true;
} }
if(Serial.available()) { if (Serial.available()) {
delay(10); // Wait for the rest of the data to arrive delay(10); // Wait for the rest of the data to arrive
uint8_t i = 0; 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(); buffer[i++] = Serial.read();
/* /*
Set the connection you want to send to using the first character 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 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 (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 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 for (uint8_t i2 = 0; i2 < i - 1; i2++) // Don't include the first character
buffer[i2] = buffer[i2+1]; buffer[i2] = buffer[i2 + 1];
SerialBT[id]->write(buffer,i-1); // Send the data SerialBT[id]->write(buffer, i - 1); // Send the data
} }
} }
} }

View file

@ -11,7 +11,7 @@ USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */ /* 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 //WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote
bool printAngle; 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 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) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); //halt while (1); //halt
} }
Serial.print(F("\r\nWiimote Bluetooth Library Started")); Serial.print(F("\r\nWiimote Bluetooth Library Started"));
} }
void loop() { void loop() {
Usb.Task(); Usb.Task();
if(Wii.wiimoteConnected) { if (Wii.wiimoteConnected) {
if(Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
Serial.print(F("\r\nHOME")); Serial.print(F("\r\nHOME"));
Wii.disconnect(); Wii.disconnect();
} }
else { else {
if(Wii.getButtonClick(LEFT)) { if (Wii.getButtonClick(LEFT)) {
Wii.setAllOff(); Wii.setAllOff();
Wii.setLedOn(LED1); Wii.setLedOn(LED1);
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
} }
if(Wii.getButtonClick(RIGHT)) { if (Wii.getButtonClick(RIGHT)) {
Wii.setAllOff(); Wii.setAllOff();
Wii.setLedOn(LED3); Wii.setLedOn(LED3);
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
} }
if(Wii.getButtonClick(DOWN)) { if (Wii.getButtonClick(DOWN)) {
Wii.setAllOff(); Wii.setAllOff();
Wii.setLedOn(LED4); Wii.setLedOn(LED4);
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
} }
if(Wii.getButtonClick(UP)) { if (Wii.getButtonClick(UP)) {
Wii.setAllOff(); Wii.setAllOff();
Wii.setLedOn(LED2); Wii.setLedOn(LED2);
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
} }
if(Wii.getButtonClick(PLUS)) if (Wii.getButtonClick(PLUS))
Serial.print(F("\r\nPlus")); Serial.print(F("\r\nPlus"));
if(Wii.getButtonClick(MINUS)) if (Wii.getButtonClick(MINUS))
Serial.print(F("\r\nMinus")); Serial.print(F("\r\nMinus"));
if(Wii.getButtonClick(ONE)) if (Wii.getButtonClick(ONE))
Serial.print(F("\r\nOne")); Serial.print(F("\r\nOne"));
if(Wii.getButtonClick(TWO)) if (Wii.getButtonClick(TWO))
Serial.print(F("\r\nTwo")); Serial.print(F("\r\nTwo"));
if(Wii.getButtonClick(A)) { if (Wii.getButtonClick(A)) {
printAngle = !printAngle; printAngle = !printAngle;
Serial.print(F("\r\nA")); Serial.print(F("\r\nA"));
} }
if(Wii.getButtonClick(B)) { if (Wii.getButtonClick(B)) {
Wii.setRumbleToggle(); Wii.setRumbleToggle();
Serial.print(F("\r\nB")); Serial.print(F("\r\nB"));
} }
} }
if(printAngle) { if (printAngle) {
Serial.print(F("\r\nPitch: ")); Serial.print(F("\r\nPitch: "));
Serial.print(Wii.getPitch()); Serial.print(Wii.getPitch());
Serial.print(F("\tRoll: ")); Serial.print(F("\tRoll: "));
Serial.print(Wii.getRoll()); Serial.print(Wii.getRoll());
if(Wii.motionPlusConnected) { if (Wii.motionPlusConnected) {
Serial.print(F("\tYaw: ")); Serial.print(F("\tYaw: "));
Serial.print(Wii.getYaw()); Serial.print(Wii.getYaw());
} }
if(Wii.nunchuckConnected) { if (Wii.nunchuckConnected) {
Serial.print(F("\tNunchuck Pitch: ")); Serial.print(F("\tNunchuck Pitch: "));
Serial.print(Wii.getNunchuckPitch()); Serial.print(Wii.getNunchuckPitch());
Serial.print(F("\tNunchuck Roll: ")); Serial.print(F("\tNunchuck Roll: "));
@ -90,12 +90,12 @@ void loop() {
} }
} }
} }
if(Wii.nunchuckConnected) { if (Wii.nunchuckConnected) {
if(Wii.getButtonClick(Z)) if (Wii.getButtonClick(Z))
Serial.print(F("\r\nZ")); Serial.print(F("\r\nZ"));
if(Wii.getButtonClick(C)) if (Wii.getButtonClick(C))
Serial.print(F("\r\nC")); 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(F("\r\nHatX: "));
Serial.print(Wii.getAnalogHat(HatX)); Serial.print(Wii.getAnalogHat(HatX));
Serial.print(F("\tHatY: ")); Serial.print(F("\tHatY: "));

View file

@ -22,7 +22,7 @@ USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */ /* 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 //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; 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 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) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); //halt while (1); //halt
} }
Serial.print(F("\r\nWiimote Bluetooth Library Started")); Serial.print(F("\r\nWiimote Bluetooth Library Started"));
} }
void loop() { void loop() {
Usb.Task(); Usb.Task();
if(Wii.wiimoteConnected) { if (Wii.wiimoteConnected) {
if(Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
Serial.print(F("\r\nHOME")); Serial.print(F("\r\nHOME"));
Wii.disconnect(); Wii.disconnect();
} }
else { else {
if(Wii.getButtonClick(ONE)) if (Wii.getButtonClick(ONE))
Wii.IRinitialize(); // Run the initialisation sequence Wii.IRinitialize(); // Run the initialisation sequence
if(Wii.getButtonClick(MINUS) || Wii.getButtonClick(PLUS)) { if (Wii.getButtonClick(MINUS) || Wii.getButtonClick(PLUS)) {
if(!Wii.isIRCameraEnabled()) if (!Wii.isIRCameraEnabled())
Serial.print(F("\r\nEnable IR camera first")); Serial.print(F("\r\nEnable IR camera first"));
else { else {
if(Wii.getButtonPress(MINUS)) { // getButtonClick will only return true once if (Wii.getButtonPress(MINUS)) { // getButtonClick will only return true once
if(printObjects > 0) if (printObjects > 0)
printObjects--; printObjects--;
} }
else { else {
if(printObjects < 4) if (printObjects < 4)
printObjects++; printObjects++;
} }
Serial.print(F("\r\nTracking ")); Serial.print(F("\r\nTracking "));
@ -65,17 +65,17 @@ void loop() {
Serial.print(F(" objects")); Serial.print(F(" objects"));
} }
} }
if(Wii.getButtonClick(A)) { if (Wii.getButtonClick(A)) {
printAngle = !printAngle; printAngle = !printAngle;
Serial.print(F("\r\nA")); Serial.print(F("\r\nA"));
} }
if(Wii.getButtonClick(B)) { if (Wii.getButtonClick(B)) {
Serial.print(F("\r\nBattery level: ")); Serial.print(F("\r\nBattery level: "));
Serial.print(Wii.getBatteryLevel()); // You can get the battery level as well Serial.print(Wii.getBatteryLevel()); // You can get the battery level as well
} }
} }
if(printObjects > 0) { if (printObjects > 0) {
if(Wii.getIRx1() != 0x3FF || Wii.getIRy1() != 0x3FF || Wii.getIRs1() != 0) { // Only print if the IR camera is actually seeing something 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(F("\r\nx1: "));
Serial.print(Wii.getIRx1()); Serial.print(Wii.getIRx1());
Serial.print(F("\ty1: ")); Serial.print(F("\ty1: "));
@ -83,8 +83,8 @@ void loop() {
Serial.print(F("\ts1:")); Serial.print(F("\ts1:"));
Serial.print(Wii.getIRs1()); Serial.print(Wii.getIRs1());
} }
if(printObjects > 1) { if (printObjects > 1) {
if(Wii.getIRx2() != 0x3FF || Wii.getIRy2() != 0x3FF || Wii.getIRs2() != 0) { if (Wii.getIRx2() != 0x3FF || Wii.getIRy2() != 0x3FF || Wii.getIRs2() != 0) {
Serial.print(F("\r\nx2: ")); Serial.print(F("\r\nx2: "));
Serial.print(Wii.getIRx2()); Serial.print(Wii.getIRx2());
Serial.print(F("\ty2: ")); Serial.print(F("\ty2: "));
@ -92,8 +92,8 @@ void loop() {
Serial.print(F("\ts2:")); Serial.print(F("\ts2:"));
Serial.print(Wii.getIRs2()); Serial.print(Wii.getIRs2());
} }
if(printObjects > 2) { if (printObjects > 2) {
if(Wii.getIRx3() != 0x3FF || Wii.getIRy3() != 0x3FF || Wii.getIRs3() != 0) { if (Wii.getIRx3() != 0x3FF || Wii.getIRy3() != 0x3FF || Wii.getIRs3() != 0) {
Serial.print(F("\r\nx3: ")); Serial.print(F("\r\nx3: "));
Serial.print(Wii.getIRx3()); Serial.print(Wii.getIRx3());
Serial.print(F("\ty3: ")); Serial.print(F("\ty3: "));
@ -101,8 +101,8 @@ void loop() {
Serial.print(F("\ts3:")); Serial.print(F("\ts3:"));
Serial.print(Wii.getIRs3()); Serial.print(Wii.getIRs3());
} }
if(printObjects > 3) { if (printObjects > 3) {
if(Wii.getIRx4() != 0x3FF || Wii.getIRy4() != 0x3FF || Wii.getIRs4() != 0) { if (Wii.getIRx4() != 0x3FF || Wii.getIRy4() != 0x3FF || Wii.getIRs4() != 0) {
Serial.print(F("\r\nx4: ")); Serial.print(F("\r\nx4: "));
Serial.print(Wii.getIRx4()); Serial.print(Wii.getIRx4());
Serial.print(F("\ty4: ")); Serial.print(F("\ty4: "));
@ -114,7 +114,7 @@ void loop() {
} }
} }
} }
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(F("\r\nPitch: "));
Serial.print(Wii.getPitch()); Serial.print(Wii.getPitch());
Serial.print(F("\tRoll: ")); Serial.print(F("\tRoll: "));

View file

@ -12,12 +12,12 @@ USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 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! 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 printAngle[length];
boolean oldControllerState[length]; boolean oldControllerState[length];
void setup() { 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] = 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 Wii[i]->attachOnInit(onInit); // onInit() is called upon a new connection - you can call the function whatever you like
} }
@ -26,71 +26,71 @@ void setup() {
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection 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) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); //halt while (1); //halt
} }
Serial.print(F("\r\nWiimote Bluetooth Library Started")); Serial.print(F("\r\nWiimote Bluetooth Library Started"));
} }
void loop() { void loop() {
Usb.Task(); Usb.Task();
for(uint8_t i=0;i<length;i++) { for (uint8_t i = 0; i < length; i++) {
if(Wii[i]->wiimoteConnected) { if (Wii[i]->wiimoteConnected) {
if(Wii[i]->getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down if (Wii[i]->getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
Serial.print(F("\r\nHOME")); Serial.print(F("\r\nHOME"));
Wii[i]->disconnect(); Wii[i]->disconnect();
oldControllerState[i] = false; // Reset value oldControllerState[i] = false; // Reset value
} }
else { else {
if(Wii[i]->getButtonClick(LEFT)) { if (Wii[i]->getButtonClick(LEFT)) {
Wii[i]->setAllOff(); Wii[i]->setAllOff();
Wii[i]->setLedOn(LED1); Wii[i]->setLedOn(LED1);
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
} }
if(Wii[i]->getButtonClick(RIGHT)) { if (Wii[i]->getButtonClick(RIGHT)) {
Wii[i]->setAllOff(); Wii[i]->setAllOff();
Wii[i]->setLedOn(LED3); Wii[i]->setLedOn(LED3);
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
} }
if(Wii[i]->getButtonClick(DOWN)) { if (Wii[i]->getButtonClick(DOWN)) {
Wii[i]->setAllOff(); Wii[i]->setAllOff();
Wii[i]->setLedOn(LED4); Wii[i]->setLedOn(LED4);
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
} }
if(Wii[i]->getButtonClick(UP)) { if (Wii[i]->getButtonClick(UP)) {
Wii[i]->setAllOff(); Wii[i]->setAllOff();
Wii[i]->setLedOn(LED2); Wii[i]->setLedOn(LED2);
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
} }
if(Wii[i]->getButtonClick(PLUS)) if (Wii[i]->getButtonClick(PLUS))
Serial.print(F("\r\nPlus")); Serial.print(F("\r\nPlus"));
if(Wii[i]->getButtonClick(MINUS)) if (Wii[i]->getButtonClick(MINUS))
Serial.print(F("\r\nMinus")); Serial.print(F("\r\nMinus"));
if(Wii[i]->getButtonClick(ONE)) if (Wii[i]->getButtonClick(ONE))
Serial.print(F("\r\nOne")); Serial.print(F("\r\nOne"));
if(Wii[i]->getButtonClick(TWO)) if (Wii[i]->getButtonClick(TWO))
Serial.print(F("\r\nTwo")); Serial.print(F("\r\nTwo"));
if(Wii[i]->getButtonClick(A)) { if (Wii[i]->getButtonClick(A)) {
printAngle[i] = !printAngle[i]; printAngle[i] = !printAngle[i];
Serial.print(F("\r\nA")); Serial.print(F("\r\nA"));
} }
if(Wii[i]->getButtonClick(B)) { if (Wii[i]->getButtonClick(B)) {
Wii[i]->setRumbleToggle(); Wii[i]->setRumbleToggle();
Serial.print(F("\r\nB")); Serial.print(F("\r\nB"));
} }
} }
if(printAngle[i]) { if (printAngle[i]) {
Serial.print(F("\r\nPitch: ")); Serial.print(F("\r\nPitch: "));
Serial.print(Wii[i]->getPitch()); Serial.print(Wii[i]->getPitch());
Serial.print(F("\tRoll: ")); Serial.print(F("\tRoll: "));
Serial.print(Wii[i]->getRoll()); Serial.print(Wii[i]->getRoll());
if(Wii[i]->motionPlusConnected) { if (Wii[i]->motionPlusConnected) {
Serial.print(F("\tYaw: ")); Serial.print(F("\tYaw: "));
Serial.print(Wii[i]->getYaw()); Serial.print(Wii[i]->getYaw());
} }
if(Wii[i]->nunchuckConnected) { if (Wii[i]->nunchuckConnected) {
Serial.print(F("\tNunchuck Pitch: ")); Serial.print(F("\tNunchuck Pitch: "));
Serial.print(Wii[i]->getNunchuckPitch()); Serial.print(Wii[i]->getNunchuckPitch());
Serial.print(F("\tNunchuck Roll: ")); Serial.print(F("\tNunchuck Roll: "));
@ -98,12 +98,12 @@ void loop() {
} }
} }
} }
if(Wii[i]->nunchuckConnected) { if (Wii[i]->nunchuckConnected) {
if(Wii[i]->getButtonClick(Z)) if (Wii[i]->getButtonClick(Z))
Serial.print(F("\r\nZ")); Serial.print(F("\r\nZ"));
if(Wii[i]->getButtonClick(C)) if (Wii[i]->getButtonClick(C))
Serial.print(F("\r\nC")); 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(F("\r\nHatX: "));
Serial.print(Wii[i]->getAnalogHat(HatX)); Serial.print(Wii[i]->getAnalogHat(HatX));
Serial.print(F("\tHatY: ")); Serial.print(F("\tHatY: "));
@ -114,7 +114,7 @@ void loop() {
} }
void onInit() { void onInit() {
for (uint8_t i=0;i<length;i++) { for (uint8_t i = 0; i < length; i++) {
if (Wii[i]->wiimoteConnected && !oldControllerState[i]) { if (Wii[i]->wiimoteConnected && !oldControllerState[i]) {
oldControllerState[i] = true; // Used to check which is the new controller oldControllerState[i] = true; // Used to check which is the new controller
Wii[i]->setLedOn((LED)i); // Cast directly to LED enum - see: "controllerEnums.h" Wii[i]->setLedOn((LED)i); // Cast directly to LED enum - see: "controllerEnums.h"

View file

@ -11,7 +11,7 @@ USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */ /* 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 //WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote
void setup() { 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 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) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); //halt while (1); //halt
} }
Serial.print(F("\r\nWiimote Bluetooth Library Started")); Serial.print(F("\r\nWiimote Bluetooth Library Started"));
} }
void loop() { void loop() {
Usb.Task(); Usb.Task();
if(Wii.wiiUProControllerConnected) { if (Wii.wiiUProControllerConnected) {
if(Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
Serial.print(F("\r\nHome")); Serial.print(F("\r\nHome"));
Wii.disconnect(); Wii.disconnect();
} }
else { else {
if(Wii.getButtonClick(LEFT)) { if (Wii.getButtonClick(LEFT)) {
Wii.setAllOff(); Wii.setAllOff();
Wii.setLedOn(LED1); Wii.setLedOn(LED1);
Serial.print(F("\r\nLeft")); Serial.print(F("\r\nLeft"));
} }
if(Wii.getButtonClick(RIGHT)) { if (Wii.getButtonClick(RIGHT)) {
Wii.setAllOff(); Wii.setAllOff();
Wii.setLedOn(LED3); Wii.setLedOn(LED3);
Serial.print(F("\r\nRight")); Serial.print(F("\r\nRight"));
} }
if(Wii.getButtonClick(DOWN)) { if (Wii.getButtonClick(DOWN)) {
Wii.setAllOff(); Wii.setAllOff();
Wii.setLedOn(LED4); Wii.setLedOn(LED4);
Serial.print(F("\r\nDown")); Serial.print(F("\r\nDown"));
} }
if(Wii.getButtonClick(UP)) { if (Wii.getButtonClick(UP)) {
Wii.setAllOff(); Wii.setAllOff();
Wii.setLedOn(LED2); Wii.setLedOn(LED2);
Serial.print(F("\r\nUp")); Serial.print(F("\r\nUp"));
} }
if(Wii.getButtonClick(PLUS)) if (Wii.getButtonClick(PLUS))
Serial.print(F("\r\nPlus")); Serial.print(F("\r\nPlus"));
if(Wii.getButtonClick(MINUS)) if (Wii.getButtonClick(MINUS))
Serial.print(F("\r\nMinus")); Serial.print(F("\r\nMinus"));
if(Wii.getButtonClick(A)) if (Wii.getButtonClick(A))
Serial.print(F("\r\nA")); Serial.print(F("\r\nA"));
if(Wii.getButtonClick(B)) { if (Wii.getButtonClick(B)) {
Wii.setRumbleToggle(); Wii.setRumbleToggle();
Serial.print(F("\r\nB")); Serial.print(F("\r\nB"));
} }
if(Wii.getButtonClick(X)) if (Wii.getButtonClick(X))
Serial.print(F("\r\nX")); Serial.print(F("\r\nX"));
if(Wii.getButtonClick(Y)) if (Wii.getButtonClick(Y))
Serial.print(F("\r\nY")); Serial.print(F("\r\nY"));
if(Wii.getButtonClick(L)) if (Wii.getButtonClick(L))
Serial.print(F("\r\nL")); Serial.print(F("\r\nL"));
if(Wii.getButtonClick(R)) if (Wii.getButtonClick(R))
Serial.print(F("\r\nR")); Serial.print(F("\r\nR"));
if(Wii.getButtonClick(ZL)) if (Wii.getButtonClick(ZL))
Serial.print(F("\r\nZL")); Serial.print(F("\r\nZL"));
if(Wii.getButtonClick(ZR)) if (Wii.getButtonClick(ZR))
Serial.print(F("\r\nZR")); Serial.print(F("\r\nZR"));
if(Wii.getButtonClick(L3)) if (Wii.getButtonClick(L3))
Serial.print(F("\r\nL3")); Serial.print(F("\r\nL3"));
if(Wii.getButtonClick(R3)) if (Wii.getButtonClick(R3))
Serial.print(F("\r\nR3")); 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(F("\r\nLeftHatX: "));
Serial.print(Wii.getAnalogHat(LeftHatX)); Serial.print(Wii.getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: ")); Serial.print(F("\tLeftHatY: "));

View file

@ -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 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) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); // halt while (1); // halt
} }
Serial.print(F("\r\nXBOX Library Started")); Serial.print(F("\r\nXBOX Library Started"));
} }
void loop() { void loop() {
Usb.Task(); Usb.Task();
if(Xbox.XboxConnected) { if (Xbox.XboxConnected) {
if(Xbox.getButtonPress(BLACK) || Xbox.getButtonPress(WHITE)) { if (Xbox.getButtonPress(BLACK) || Xbox.getButtonPress(WHITE)) {
Serial.print("BLACK: "); Serial.print("BLACK: ");
Serial.print(Xbox.getButtonPress(BLACK)); Serial.print(Xbox.getButtonPress(BLACK));
Serial.print("\tWHITE: "); Serial.print("\tWHITE: ");
Serial.println(Xbox.getButtonPress(WHITE)); Serial.println(Xbox.getButtonPress(WHITE));
Xbox.setRumbleOn(Xbox.getButtonPress(BLACK),Xbox.getButtonPress(WHITE)); Xbox.setRumbleOn(Xbox.getButtonPress(BLACK), Xbox.getButtonPress(WHITE));
} else } else
Xbox.setRumbleOn(0,0); 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 || 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) { if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) {
Serial.print(F("LeftHatX: ")); Serial.print(F("LeftHatX: "));
Serial.print(Xbox.getAnalogHat(LeftHatX)); Serial.print(Xbox.getAnalogHat(LeftHatX));
Serial.print("\t"); Serial.print("\t");
} }
if(Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) { if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) {
Serial.print(F("LeftHatY: ")); Serial.print(F("LeftHatY: "));
Serial.print(Xbox.getAnalogHat(LeftHatY)); Serial.print(Xbox.getAnalogHat(LeftHatY));
Serial.print("\t"); Serial.print("\t");
} }
if(Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) { if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) {
Serial.print(F("RightHatX: ")); Serial.print(F("RightHatX: "));
Serial.print(Xbox.getAnalogHat(RightHatX)); Serial.print(Xbox.getAnalogHat(RightHatX));
Serial.print("\t"); Serial.print("\t");
} }
if(Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) {
Serial.print(F("RightHatY: ")); Serial.print(F("RightHatY: "));
Serial.print(Xbox.getAnalogHat(RightHatY)); Serial.print(Xbox.getAnalogHat(RightHatY));
} }
Serial.println(); Serial.println();
} }
if(Xbox.getButtonClick(UP)) if (Xbox.getButtonClick(UP))
Serial.println(F("Up")); Serial.println(F("Up"));
if(Xbox.getButtonClick(DOWN)) if (Xbox.getButtonClick(DOWN))
Serial.println(F("Down")); Serial.println(F("Down"));
if(Xbox.getButtonClick(LEFT)) if (Xbox.getButtonClick(LEFT))
Serial.println(F("Left")); Serial.println(F("Left"));
if(Xbox.getButtonClick(RIGHT)) if (Xbox.getButtonClick(RIGHT))
Serial.println(F("Right")); Serial.println(F("Right"));
if(Xbox.getButtonClick(START)) if (Xbox.getButtonClick(START))
Serial.println(F("Start")); Serial.println(F("Start"));
if(Xbox.getButtonClick(BACK)) if (Xbox.getButtonClick(BACK))
Serial.println(F("Back")); Serial.println(F("Back"));
if(Xbox.getButtonClick(L3)) if (Xbox.getButtonClick(L3))
Serial.println(F("L3")); Serial.println(F("L3"));
if(Xbox.getButtonClick(R3)) if (Xbox.getButtonClick(R3))
Serial.println(F("R3")); Serial.println(F("R3"));
if(Xbox.getButtonPress(A)) { if (Xbox.getButtonPress(A)) {
Serial.print(F("A: ")); Serial.print(F("A: "));
Serial.println(Xbox.getButtonPress(A)); Serial.println(Xbox.getButtonPress(A));
} }
if(Xbox.getButtonPress(B)) { if (Xbox.getButtonPress(B)) {
Serial.print(F("B: ")); Serial.print(F("B: "));
Serial.println(Xbox.getButtonPress(B)); Serial.println(Xbox.getButtonPress(B));
} }
if(Xbox.getButtonPress(X)) { if (Xbox.getButtonPress(X)) {
Serial.print(F("X: ")); Serial.print(F("X: "));
Serial.println(Xbox.getButtonPress(X)); Serial.println(Xbox.getButtonPress(X));
} }
if(Xbox.getButtonPress(Y)) { if (Xbox.getButtonPress(Y)) {
Serial.print(F("Y: ")); Serial.print(F("Y: "));
Serial.println(Xbox.getButtonPress(Y)); Serial.println(Xbox.getButtonPress(Y));
} }
if(Xbox.getButtonPress(L1)) { if (Xbox.getButtonPress(L1)) {
Serial.print(F("L1: ")); Serial.print(F("L1: "));
Serial.println(Xbox.getButtonPress(L1)); Serial.println(Xbox.getButtonPress(L1));
} }
if(Xbox.getButtonPress(R1)) { if (Xbox.getButtonPress(R1)) {
Serial.print(F("R1: ")); Serial.print(F("R1: "));
Serial.println(Xbox.getButtonPress(R1)); Serial.println(Xbox.getButtonPress(R1));
} }

View file

@ -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 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) { if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start")); Serial.print(F("\r\nOSC did not start"));
while(1); //halt while (1); //halt
} }
Serial.print(F("\r\nXBOX USB Library Started")); Serial.print(F("\r\nXBOX USB Library Started"));
} }
void loop() { void loop() {
Usb.Task(); Usb.Task();
if(Xbox.Xbox360Connected) { if (Xbox.Xbox360Connected) {
if(Xbox.getButtonPress(L2) || Xbox.getButtonPress(R2)) { if (Xbox.getButtonPress(L2) || Xbox.getButtonPress(R2)) {
Serial.print("L2: "); Serial.print("L2: ");
Serial.print(Xbox.getButtonPress(L2)); Serial.print(Xbox.getButtonPress(L2));
Serial.print("\tR2: "); Serial.print("\tR2: ");
Serial.println(Xbox.getButtonPress(R2)); Serial.println(Xbox.getButtonPress(R2));
Xbox.setRumbleOn(Xbox.getButtonPress(L2),Xbox.getButtonPress(R2)); Xbox.setRumbleOn(Xbox.getButtonPress(L2), Xbox.getButtonPress(R2));
} else } else
Xbox.setRumbleOn(0,0); 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 || 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) { if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) {
Serial.print(F("LeftHatX: ")); Serial.print(F("LeftHatX: "));
Serial.print(Xbox.getAnalogHat(LeftHatX)); Serial.print(Xbox.getAnalogHat(LeftHatX));
Serial.print("\t"); Serial.print("\t");
} }
if(Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) { if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) {
Serial.print(F("LeftHatY: ")); Serial.print(F("LeftHatY: "));
Serial.print(Xbox.getAnalogHat(LeftHatY)); Serial.print(Xbox.getAnalogHat(LeftHatY));
Serial.print("\t"); Serial.print("\t");
} }
if(Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) { if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) {
Serial.print(F("RightHatX: ")); Serial.print(F("RightHatX: "));
Serial.print(Xbox.getAnalogHat(RightHatX)); Serial.print(Xbox.getAnalogHat(RightHatX));
Serial.print("\t"); Serial.print("\t");
} }
if(Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) {
Serial.print(F("RightHatY: ")); Serial.print(F("RightHatY: "));
Serial.print(Xbox.getAnalogHat(RightHatY)); Serial.print(Xbox.getAnalogHat(RightHatY));
} }
Serial.println(); Serial.println();
} }
if(Xbox.getButtonClick(UP)) { if (Xbox.getButtonClick(UP)) {
Xbox.setLedOn(LED1); Xbox.setLedOn(LED1);
Serial.println(F("Up")); Serial.println(F("Up"));
} }
if(Xbox.getButtonClick(DOWN)) { if (Xbox.getButtonClick(DOWN)) {
Xbox.setLedOn(LED4); Xbox.setLedOn(LED4);
Serial.println(F("Down")); Serial.println(F("Down"));
} }
if(Xbox.getButtonClick(LEFT)) { if (Xbox.getButtonClick(LEFT)) {
Xbox.setLedOn(LED3); Xbox.setLedOn(LED3);
Serial.println(F("Left")); Serial.println(F("Left"));
} }
if(Xbox.getButtonClick(RIGHT)) { if (Xbox.getButtonClick(RIGHT)) {
Xbox.setLedOn(LED2); Xbox.setLedOn(LED2);
Serial.println(F("Right")); Serial.println(F("Right"));
} }
if(Xbox.getButtonClick(START)) { if (Xbox.getButtonClick(START)) {
Xbox.setLedMode(ALTERNATING); Xbox.setLedMode(ALTERNATING);
Serial.println(F("Start")); Serial.println(F("Start"));
} }
if(Xbox.getButtonClick(BACK)) { if (Xbox.getButtonClick(BACK)) {
Xbox.setLedBlink(ALL); Xbox.setLedBlink(ALL);
Serial.println(F("Back")); Serial.println(F("Back"));
} }
if(Xbox.getButtonClick(L3)) if (Xbox.getButtonClick(L3))
Serial.println(F("L3")); Serial.println(F("L3"));
if(Xbox.getButtonClick(R3)) if (Xbox.getButtonClick(R3))
Serial.println(F("R3")); Serial.println(F("R3"));
if(Xbox.getButtonClick(L1)) if (Xbox.getButtonClick(L1))
Serial.println(F("L1")); Serial.println(F("L1"));
if(Xbox.getButtonClick(R1)) if (Xbox.getButtonClick(R1))
Serial.println(F("R1")); Serial.println(F("R1"));
if(Xbox.getButtonClick(XBOX)) { if (Xbox.getButtonClick(XBOX)) {
Xbox.setLedMode(ROTATING); Xbox.setLedMode(ROTATING);
Serial.println(F("Xbox")); Serial.println(F("Xbox"));
} }
if(Xbox.getButtonClick(A)) if (Xbox.getButtonClick(A))
Serial.println(F("A")); Serial.println(F("A"));
if(Xbox.getButtonClick(B)) if (Xbox.getButtonClick(B))
Serial.println(F("B")); Serial.println(F("B"));
if(Xbox.getButtonClick(X)) if (Xbox.getButtonClick(X))
Serial.println(F("X")); Serial.println(F("X"));
if(Xbox.getButtonClick(Y)) if (Xbox.getButtonClick(Y))
Serial.println(F("Y")); Serial.println(F("Y"));
} }
delay(1); delay(1);