USB_Host_Shield_2.0/examples/Bluetooth/WiiUProController/WiiUProController.ino

105 lines
3.5 KiB
Arduino
Raw Normal View History

2013-02-02 22:14:01 +01:00
/*
Example sketch for the Wiimote Bluetooth library - developed by Kristian Lauszus
2013-11-15 19:05:25 +01:00
For more information visit my blog: http://blog.tkjelectronics.dk/ or
2013-02-02 22:14:01 +01:00
send me an e-mail: kristianl@tkjelectronics.com
*/
#include <Wii.h>
2013-08-13 21:31:52 +02:00
#include <usbhub.h>
#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too.
#include <SPI.h>
#include <spi4teensy3.h>
#include <SPI.h>
#endif
2013-08-13 21:31:52 +02:00
2013-02-02 22:14:01 +01:00
USB Usb;
2013-11-24 15:17:19 +01:00
//USBHub Hub1(&Usb); // Some dongles have a hub inside
2013-02-02 22:14:01 +01:00
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
2013-11-15 19:05:25 +01:00
WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
2013-02-02 22:14:01 +01:00
//WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote
void setup() {
Serial.begin(115200);
#if !defined(__MIPSEL__)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
2013-02-02 22:14:01 +01:00
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
2013-11-15 19:05:25 +01:00
while (1); //halt
2013-02-02 22:14:01 +01:00
}
Serial.print(F("\r\nWiimote Bluetooth Library Started"));
}
void loop() {
Usb.Task();
2013-11-15 19:05:25 +01:00
if (Wii.wiiUProControllerConnected) {
if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nHome"));
Wii.disconnect();
2013-11-15 19:05:25 +01:00
}
2013-02-02 22:14:01 +01:00
else {
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(LEFT)) {
Wii.setLedOff();
2013-02-02 22:14:01 +01:00
Wii.setLedOn(LED1);
Serial.print(F("\r\nLeft"));
}
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(RIGHT)) {
Wii.setLedOff();
2013-02-02 22:14:01 +01:00
Wii.setLedOn(LED3);
Serial.print(F("\r\nRight"));
}
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(DOWN)) {
Wii.setLedOff();
2013-02-02 22:14:01 +01:00
Wii.setLedOn(LED4);
Serial.print(F("\r\nDown"));
2013-11-15 19:05:25 +01:00
}
if (Wii.getButtonClick(UP)) {
Wii.setLedOff();
2013-11-15 19:05:25 +01:00
Wii.setLedOn(LED2);
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nUp"));
}
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(PLUS))
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nPlus"));
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(MINUS))
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nMinus"));
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(A))
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nA"));
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(B)) {
2013-02-02 22:14:01 +01:00
Wii.setRumbleToggle();
Serial.print(F("\r\nB"));
}
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(X))
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nX"));
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(Y))
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nY"));
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(L))
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nL"));
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(R))
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nR"));
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(ZL))
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nZL"));
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(ZR))
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nZR"));
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(L3))
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nL3"));
2013-11-15 19:05:25 +01:00
if (Wii.getButtonClick(R3))
Serial.print(F("\r\nR3"));
2013-02-02 22:14:01 +01:00
}
2013-11-15 19:05:25 +01:00
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) {
2013-02-02 22:14:01 +01:00
Serial.print(F("\r\nLeftHatX: "));
Serial.print(Wii.getAnalogHat(LeftHatX));
Serial.print(F("\tLeftHatY: "));
Serial.print(Wii.getAnalogHat(LeftHatY));
Serial.print(F("\tRightHatX: "));
Serial.print(Wii.getAnalogHat(RightHatX));
Serial.print(F("\tRightHatY: "));
Serial.print(Wii.getAnalogHat(RightHatY));
}
}
}