您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

75 行
1.7KB

  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.println();
  51. joystick1.joystickDataClear();
  52. }
  53. }
  54. void OnPress(int key)
  55. {
  56. Serial.print("key '");
  57. Serial.print((char)key);
  58. Serial.print("' ");
  59. Serial.println(key);
  60. //Serial.print("key ");
  61. //Serial.print((char)keyboard1.getKey());
  62. //Serial.print(" ");
  63. //Serial.print((char)keyboard2.getKey());
  64. //Serial.println();
  65. }