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
28 #if !defined(__MIPSEL__)
29 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
31 if (Usb.Init() == -1) {
32 Serial.print(F("\r\nOSC did not start"));
35 Serial.print(F("\r\nWiimote Bluetooth Library Started"));
39 if (Wii.wiimoteConnected) {
40 if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
41 Serial.print(F("\r\nHOME"));
45 if (Wii.getButtonClick(LEFT)) {
48 Serial.print(F("\r\nLeft"));
50 if (Wii.getButtonClick(RIGHT)) {
53 Serial.print(F("\r\nRight"));
55 if (Wii.getButtonClick(DOWN)) {
58 Serial.print(F("\r\nDown"));
60 if (Wii.getButtonClick(UP)) {
63 Serial.print(F("\r\nUp"));
66 if (Wii.getButtonClick(PLUS))
67 Serial.print(F("\r\nPlus"));
68 if (Wii.getButtonClick(MINUS))
69 Serial.print(F("\r\nMinus"));
71 if (Wii.getButtonClick(ONE))
72 Serial.print(F("\r\nOne"));
73 if (Wii.getButtonClick(TWO))
74 Serial.print(F("\r\nTwo"));
76 if (Wii.getButtonClick(A)) {
77 printAngle = !printAngle;
78 Serial.print(F("\r\nA"));
80 if (Wii.getButtonClick(B)) {
81 Wii.setRumbleToggle();
82 Serial.print(F("\r\nB"));
85 #if 0 // Set this to 1 in order to see the angle of the controllers
87 Serial.print(F("\r\nPitch: "));
88 Serial.print(Wii.getPitch());
89 Serial.print(F("\tRoll: "));
90 Serial.print(Wii.getRoll());
91 if (Wii.motionPlusConnected) {
92 Serial.print(F("\tYaw: "));
93 Serial.print(Wii.getYaw());
95 if (Wii.nunchuckConnected) {
96 Serial.print(F("\tNunchuck Pitch: "));
97 Serial.print(Wii.getNunchuckPitch());
98 Serial.print(F("\tNunchuck Roll: "));
99 Serial.print(Wii.getNunchuckRoll());
104 #if 0 // Set this to 1 if you are using a Nunchuck controller
105 if (Wii.nunchuckConnected) {
106 if (Wii.getButtonClick(Z))
107 Serial.print(F("\r\nZ"));
108 if (Wii.getButtonClick(C))
109 Serial.print(F("\r\nC"));
110 if (Wii.getAnalogHat(HatX) > 137 || Wii.getAnalogHat(HatX) < 117 || Wii.getAnalogHat(HatY) > 137 || Wii.getAnalogHat(HatY) < 117) {
111 Serial.print(F("\r\nHatX: "));
112 Serial.print(Wii.getAnalogHat(HatX));
113 Serial.print(F("\tHatY: "));
114 Serial.print(Wii.getAnalogHat(HatY));