Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

84 lines
2.0KB

  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. }