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.

Mouse.ino 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Simple test of USB Host Mouse/Keyboard
  2. //
  3. // This example is in the public domain
  4. #include "USBHost_t36.h"
  5. USBHost myusb;
  6. USBHub hub1(myusb);
  7. USBHub hub2(myusb);
  8. USBHub hub3(myusb);
  9. KeyboardController keyboard1(myusb);
  10. KeyboardController keyboard2(myusb);
  11. USBHIDParser hid1(myusb);
  12. USBHIDParser hid2(myusb);
  13. USBHIDParser hid3(myusb);
  14. USBHIDParser hid4(myusb);
  15. USBHIDParser hid5(myusb);
  16. MouseController mouse1(myusb);
  17. JoystickController joystick1(myusb);
  18. void setup()
  19. {
  20. while (!Serial) ; // wait for Arduino Serial Monitor
  21. Serial.println("USB Host Testing");
  22. myusb.begin();
  23. keyboard1.attachPress(OnPress);
  24. keyboard2.attachPress(OnPress);
  25. }
  26. void loop()
  27. {
  28. myusb.Task();
  29. if(mouse1.available()) {
  30. Serial.print("Mouse: buttons = ");
  31. Serial.print(mouse1.getButtons());
  32. Serial.print(", mouseX = ");
  33. Serial.print(mouse1.getMouseX());
  34. Serial.print(", mouseY = ");
  35. Serial.print(mouse1.getMouseY());
  36. Serial.print(", wheel = ");
  37. Serial.print(mouse1.getWheel());
  38. Serial.print(", wheelH = ");
  39. Serial.print(mouse1.getWheelH());
  40. Serial.println();
  41. mouse1.mouseDataClear();
  42. }
  43. if (joystick1.available()) {
  44. Serial.print("Joystick: buttons = ");
  45. Serial.print(joystick1.getButtons(), HEX);
  46. Serial.print(", X = ");
  47. Serial.print(joystick1.getAxis(0));
  48. Serial.print(", Y = ");
  49. Serial.print(joystick1.getAxis(1));
  50. Serial.print(", Z = ");
  51. Serial.print(joystick1.getAxis(2));
  52. Serial.print(", Rz = ");
  53. Serial.print(joystick1.getAxis(5));
  54. Serial.print(", Rx = ");
  55. Serial.print(joystick1.getAxis(3));
  56. Serial.print(", Ry = ");
  57. Serial.print(joystick1.getAxis(4));
  58. Serial.print(", Hat = ");
  59. Serial.print(joystick1.getAxis(9));
  60. Serial.println();
  61. joystick1.joystickDataClear();
  62. }
  63. }
  64. void OnPress(int key)
  65. {
  66. Serial.print("key '");
  67. Serial.print((char)key);
  68. Serial.print("' ");
  69. Serial.println(key);
  70. //Serial.print("key ");
  71. //Serial.print((char)keyboard1.getKey());
  72. //Serial.print(" ");
  73. //Serial.print((char)keyboard2.getKey());
  74. //Serial.println();
  75. }