]> git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/Bluetooth/WiiUProController/WiiUProController.ino
Merge commit 'f6d56675f9f981c5464f0ca7a1fbb0162154e8c5'
[tmk_keyboard.git] / tmk_core / protocol / usb_hid / USB_Host_Shield_2.0 / examples / Bluetooth / WiiUProController / WiiUProController.ino
1 /*
2 Example sketch for the Wiimote Bluetooth library - developed by Kristian Lauszus
3 For more information visit my blog: http://blog.tkjelectronics.dk/ or
4 send me an e-mail: kristianl@tkjelectronics.com
5 */
6
7 #include <Wii.h>
8 #include <usbhub.h>
9
10 // Satisfy the IDE, which needs to see the include statment in the ino too.
11 #ifdef dobogusinclude
12 #include <spi4teensy3.h>
13 #include <SPI.h>
14 #endif
15
16 USB Usb;
17 //USBHub Hub1(&Usb); // Some dongles have a hub inside
18
19 BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
20 /* You can create the instance of the class in two ways */
21 WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once
22 //WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote
23
24 void setup() {
25 Serial.begin(115200);
26 #if !defined(__MIPSEL__)
27 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
28 #endif
29 if (Usb.Init() == -1) {
30 Serial.print(F("\r\nOSC did not start"));
31 while (1); //halt
32 }
33 Serial.print(F("\r\nWiimote Bluetooth Library Started"));
34 }
35 void loop() {
36 Usb.Task();
37 if (Wii.wiiUProControllerConnected) {
38 if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
39 Serial.print(F("\r\nHome"));
40 Wii.disconnect();
41 }
42 else {
43 if (Wii.getButtonClick(LEFT)) {
44 Wii.setLedOff();
45 Wii.setLedOn(LED1);
46 Serial.print(F("\r\nLeft"));
47 }
48 if (Wii.getButtonClick(RIGHT)) {
49 Wii.setLedOff();
50 Wii.setLedOn(LED3);
51 Serial.print(F("\r\nRight"));
52 }
53 if (Wii.getButtonClick(DOWN)) {
54 Wii.setLedOff();
55 Wii.setLedOn(LED4);
56 Serial.print(F("\r\nDown"));
57 }
58 if (Wii.getButtonClick(UP)) {
59 Wii.setLedOff();
60 Wii.setLedOn(LED2);
61 Serial.print(F("\r\nUp"));
62 }
63
64 if (Wii.getButtonClick(PLUS))
65 Serial.print(F("\r\nPlus"));
66 if (Wii.getButtonClick(MINUS))
67 Serial.print(F("\r\nMinus"));
68
69 if (Wii.getButtonClick(A))
70 Serial.print(F("\r\nA"));
71 if (Wii.getButtonClick(B)) {
72 Wii.setRumbleToggle();
73 Serial.print(F("\r\nB"));
74 }
75 if (Wii.getButtonClick(X))
76 Serial.print(F("\r\nX"));
77 if (Wii.getButtonClick(Y))
78 Serial.print(F("\r\nY"));
79
80 if (Wii.getButtonClick(L))
81 Serial.print(F("\r\nL"));
82 if (Wii.getButtonClick(R))
83 Serial.print(F("\r\nR"));
84 if (Wii.getButtonClick(ZL))
85 Serial.print(F("\r\nZL"));
86 if (Wii.getButtonClick(ZR))
87 Serial.print(F("\r\nZR"));
88 if (Wii.getButtonClick(L3))
89 Serial.print(F("\r\nL3"));
90 if (Wii.getButtonClick(R3))
91 Serial.print(F("\r\nR3"));
92 }
93 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) {
94 Serial.print(F("\r\nLeftHatX: "));
95 Serial.print(Wii.getAnalogHat(LeftHatX));
96 Serial.print(F("\tLeftHatY: "));
97 Serial.print(Wii.getAnalogHat(LeftHatY));
98 Serial.print(F("\tRightHatX: "));
99 Serial.print(Wii.getAnalogHat(RightHatX));
100 Serial.print(F("\tRightHatY: "));
101 Serial.print(Wii.getAnalogHat(RightHatY));
102 }
103 }
104 }
Imprint / Impressum