You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

WiiBalanceBoard.ino 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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: [email protected]
  5. */
  6. #include <Wii.h>
  7. #include <usbhub.h>
  8. // Satisfy the IDE, which needs to see the include statment in the ino too.
  9. #ifdef dobogusinclude
  10. #include <spi4teensy3.h>
  11. #include <SPI.h>
  12. #endif
  13. USB Usb;
  14. //USBHub Hub1(&Usb); // Some dongles have a hub inside
  15. BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
  16. /* You can create the instance of the class in two ways */
  17. WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wii Balance Board - you only have to do this once
  18. //WII Wii(&Btd); // After that you can simply create the instance like so and then press the power button on the Wii Balance Board
  19. void setup() {
  20. Serial.begin(115200);
  21. #if !defined(__MIPSEL__)
  22. while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  23. #endif
  24. if (Usb.Init() == -1) {
  25. Serial.print(F("\r\nOSC did not start"));
  26. while (1); //halt
  27. }
  28. Serial.print(F("\r\nWii Balance Board Bluetooth Library Started"));
  29. }
  30. void loop() {
  31. Usb.Task();
  32. if (Wii.wiiBalanceBoardConnected) {
  33. Serial.print(F("\r\nWeight: "));
  34. for (uint8_t i = 0; i < 4; i++) {
  35. Serial.print(Wii.getWeight((BalanceBoardEnum)i));
  36. Serial.print(F("\t"));
  37. }
  38. Serial.print(F("Total Weight: "));
  39. Serial.print(Wii.getTotalWeight());
  40. if (Wii.getButtonClick(A)) {
  41. Serial.print(F("\r\nA"));
  42. //Wii.setLedToggle(LED1); // The Wii Balance Board has one LED as well
  43. Wii.disconnect();
  44. }
  45. }
  46. }