]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino
lufa: usb-usb: Use LUFA startup instead of cusotom
[max/tmk_keyboard.git] / tmk_core / protocol / usb_hid / USB_Host_Shield_2.0 / examples / Bluetooth / WiiBalanceBoard / WiiBalanceBoard.ino
1 /*
2  Example sketch for the Wii Balance Board 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 Wii Balance Board - you only have to do this once
22 //WII Wii(&Btd); // After that you can simply create the instance like so and then press the power button on the Wii Balance Board
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\nWii Balance Board Bluetooth Library Started"));
34 }
35 void loop() {
36   Usb.Task();
37   if (Wii.wiiBalanceBoardConnected) {
38     Serial.print(F("\r\nWeight: "));
39     for (uint8_t i = 0; i < 4; i++) {
40       Serial.print(Wii.getWeight((BalanceBoardEnum)i));
41       Serial.print(F("\t"));
42     }
43     Serial.print(F("Total Weight: "));
44     Serial.print(Wii.getTotalWeight());
45     if (Wii.getButtonClick(A)) {
46       Serial.print(F("\r\nA"));
47       //Wii.setLedToggle(LED1); // The Wii Balance Board has one LED as well
48       Wii.disconnect();
49     }
50   }
51 }