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.

WiiUProController.ino 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: [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 Wiimote - you only have to do this once
  18. //WII Wii(&Btd); // After that you can simply create the instance like so and then press any button on the Wiimote
  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\nWiimote Bluetooth Library Started"));
  29. }
  30. void loop() {
  31. Usb.Task();
  32. if (Wii.wiiUProControllerConnected) {
  33. if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
  34. Serial.print(F("\r\nHome"));
  35. Wii.disconnect();
  36. }
  37. else {
  38. if (Wii.getButtonClick(LEFT)) {
  39. Wii.setLedOff();
  40. Wii.setLedOn(LED1);
  41. Serial.print(F("\r\nLeft"));
  42. }
  43. if (Wii.getButtonClick(RIGHT)) {
  44. Wii.setLedOff();
  45. Wii.setLedOn(LED3);
  46. Serial.print(F("\r\nRight"));
  47. }
  48. if (Wii.getButtonClick(DOWN)) {
  49. Wii.setLedOff();
  50. Wii.setLedOn(LED4);
  51. Serial.print(F("\r\nDown"));
  52. }
  53. if (Wii.getButtonClick(UP)) {
  54. Wii.setLedOff();
  55. Wii.setLedOn(LED2);
  56. Serial.print(F("\r\nUp"));
  57. }
  58. if (Wii.getButtonClick(PLUS))
  59. Serial.print(F("\r\nPlus"));
  60. if (Wii.getButtonClick(MINUS))
  61. Serial.print(F("\r\nMinus"));
  62. if (Wii.getButtonClick(A))
  63. Serial.print(F("\r\nA"));
  64. if (Wii.getButtonClick(B)) {
  65. Wii.setRumbleToggle();
  66. Serial.print(F("\r\nB"));
  67. }
  68. if (Wii.getButtonClick(X))
  69. Serial.print(F("\r\nX"));
  70. if (Wii.getButtonClick(Y))
  71. Serial.print(F("\r\nY"));
  72. if (Wii.getButtonClick(L))
  73. Serial.print(F("\r\nL"));
  74. if (Wii.getButtonClick(R))
  75. Serial.print(F("\r\nR"));
  76. if (Wii.getButtonClick(ZL))
  77. Serial.print(F("\r\nZL"));
  78. if (Wii.getButtonClick(ZR))
  79. Serial.print(F("\r\nZR"));
  80. if (Wii.getButtonClick(L3))
  81. Serial.print(F("\r\nL3"));
  82. if (Wii.getButtonClick(R3))
  83. Serial.print(F("\r\nR3"));
  84. }
  85. 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) {
  86. Serial.print(F("\r\nLeftHatX: "));
  87. Serial.print(Wii.getAnalogHat(LeftHatX));
  88. Serial.print(F("\tLeftHatY: "));
  89. Serial.print(Wii.getAnalogHat(LeftHatY));
  90. Serial.print(F("\tRightHatX: "));
  91. Serial.print(Wii.getAnalogHat(RightHatX));
  92. Serial.print(F("\tRightHatY: "));
  93. Serial.print(Wii.getAnalogHat(RightHatY));
  94. }
  95. }
  96. }