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.

Wii.ino 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. bool printAngle;
  20. void setup() {
  21. Serial.begin(115200);
  22. #if !defined(__MIPSEL__)
  23. while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  24. #endif
  25. if (Usb.Init() == -1) {
  26. Serial.print(F("\r\nOSC did not start"));
  27. while (1); //halt
  28. }
  29. Serial.print(F("\r\nWiimote Bluetooth Library Started"));
  30. }
  31. void loop() {
  32. Usb.Task();
  33. if (Wii.wiimoteConnected) {
  34. if (Wii.getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
  35. Serial.print(F("\r\nHOME"));
  36. Wii.disconnect();
  37. }
  38. else {
  39. if (Wii.getButtonClick(LEFT)) {
  40. Wii.setLedOff();
  41. Wii.setLedOn(LED1);
  42. Serial.print(F("\r\nLeft"));
  43. }
  44. if (Wii.getButtonClick(RIGHT)) {
  45. Wii.setLedOff();
  46. Wii.setLedOn(LED3);
  47. Serial.print(F("\r\nRight"));
  48. }
  49. if (Wii.getButtonClick(DOWN)) {
  50. Wii.setLedOff();
  51. Wii.setLedOn(LED4);
  52. Serial.print(F("\r\nDown"));
  53. }
  54. if (Wii.getButtonClick(UP)) {
  55. Wii.setLedOff();
  56. Wii.setLedOn(LED2);
  57. Serial.print(F("\r\nUp"));
  58. }
  59. if (Wii.getButtonClick(PLUS))
  60. Serial.print(F("\r\nPlus"));
  61. if (Wii.getButtonClick(MINUS))
  62. Serial.print(F("\r\nMinus"));
  63. if (Wii.getButtonClick(ONE))
  64. Serial.print(F("\r\nOne"));
  65. if (Wii.getButtonClick(TWO))
  66. Serial.print(F("\r\nTwo"));
  67. if (Wii.getButtonClick(A)) {
  68. printAngle = !printAngle;
  69. Serial.print(F("\r\nA"));
  70. }
  71. if (Wii.getButtonClick(B)) {
  72. Wii.setRumbleToggle();
  73. Serial.print(F("\r\nB"));
  74. }
  75. }
  76. #if 0 // Set this to 1 in order to see the angle of the controllers
  77. if (printAngle) {
  78. Serial.print(F("\r\nPitch: "));
  79. Serial.print(Wii.getPitch());
  80. Serial.print(F("\tRoll: "));
  81. Serial.print(Wii.getRoll());
  82. if (Wii.motionPlusConnected) {
  83. Serial.print(F("\tYaw: "));
  84. Serial.print(Wii.getYaw());
  85. }
  86. if (Wii.nunchuckConnected) {
  87. Serial.print(F("\tNunchuck Pitch: "));
  88. Serial.print(Wii.getNunchuckPitch());
  89. Serial.print(F("\tNunchuck Roll: "));
  90. Serial.print(Wii.getNunchuckRoll());
  91. }
  92. }
  93. #endif
  94. }
  95. #if 0 // Set this to 1 if you are using a Nunchuck controller
  96. if (Wii.nunchuckConnected) {
  97. if (Wii.getButtonClick(Z))
  98. Serial.print(F("\r\nZ"));
  99. if (Wii.getButtonClick(C))
  100. Serial.print(F("\r\nC"));
  101. if (Wii.getAnalogHat(HatX) > 137 || Wii.getAnalogHat(HatX) < 117 || Wii.getAnalogHat(HatY) > 137 || Wii.getAnalogHat(HatY) < 117) {
  102. Serial.print(F("\r\nHatX: "));
  103. Serial.print(Wii.getAnalogHat(HatX));
  104. Serial.print(F("\tHatY: "));
  105. Serial.print(Wii.getAnalogHat(HatY));
  106. }
  107. }
  108. #endif
  109. }