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
10 // Satisfy the IDE, which needs to see the include statment in the ino too.
12 #include <spi4teensy3.h>
17 //USBHub Hub1(&Usb); // Some dongles have a hub inside
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
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
29 if (Usb.Init() == -1) {
30 Serial.print(F("\r\nOSC did not start"));
33 Serial.print(F("\r\nWiimote Bluetooth Library Started"));
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"));
43 if (Wii.getButtonClick(LEFT)) {
46 Serial.print(F("\r\nLeft"));
48 if (Wii.getButtonClick(RIGHT)) {
51 Serial.print(F("\r\nRight"));
53 if (Wii.getButtonClick(DOWN)) {
56 Serial.print(F("\r\nDown"));
58 if (Wii.getButtonClick(UP)) {
61 Serial.print(F("\r\nUp"));
64 if (Wii.getButtonClick(PLUS))
65 Serial.print(F("\r\nPlus"));
66 if (Wii.getButtonClick(MINUS))
67 Serial.print(F("\r\nMinus"));
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"));
75 if (Wii.getButtonClick(X))
76 Serial.print(F("\r\nX"));
77 if (Wii.getButtonClick(Y))
78 Serial.print(F("\r\nY"));
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"));
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));