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.

95 line
1.9KB

  1. // Simple test of USB Host
  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. MIDIDevice midi1(myusb);
  12. void setup()
  13. {
  14. while (!Serial) ; // wait for Arduino Serial Monitor
  15. Serial.println("USB Host Testing");
  16. myusb.begin();
  17. keyboard1.attachPress(OnPress);
  18. keyboard1.attachRawPress(OnRawPress);
  19. keyboard1.attachRawRelease(OnRawRelease);
  20. keyboard2.attachPress(OnPress);
  21. midi1.setHandleNoteOff(OnNoteOff);
  22. midi1.setHandleNoteOn(OnNoteOn);
  23. midi1.setHandleControlChange(OnControlChange);
  24. }
  25. void loop()
  26. {
  27. myusb.Task();
  28. midi1.read();
  29. }
  30. void OnPress(int key)
  31. {
  32. Serial.print("key '");
  33. Serial.print((char)key);
  34. Serial.print("' ");
  35. Serial.println(key);
  36. //Serial.print("key ");
  37. //Serial.print((char)keyboard1.getKey());
  38. //Serial.print(" ");
  39. //Serial.print((char)keyboard2.getKey());
  40. //Serial.println();
  41. }
  42. void OnRawPress(uint8_t keycode)
  43. {
  44. Serial.print("raw key press: ");
  45. Serial.println((int)keycode);
  46. }
  47. void OnRawRelease(uint8_t keycode)
  48. {
  49. Serial.print("raw key release: ");
  50. Serial.println((int)keycode);
  51. }
  52. void OnNoteOn(byte channel, byte note, byte velocity)
  53. {
  54. Serial.print("Note On, ch=");
  55. Serial.print(channel);
  56. Serial.print(", note=");
  57. Serial.print(note);
  58. Serial.print(", velocity=");
  59. Serial.print(velocity);
  60. Serial.println();
  61. }
  62. void OnNoteOff(byte channel, byte note, byte velocity)
  63. {
  64. Serial.print("Note Off, ch=");
  65. Serial.print(channel);
  66. Serial.print(", note=");
  67. Serial.print(note);
  68. //Serial.print(", velocity=");
  69. //Serial.print(velocity);
  70. Serial.println();
  71. }
  72. void OnControlChange(byte channel, byte control, byte value)
  73. {
  74. Serial.print("Control Change, ch=");
  75. Serial.print(channel);
  76. Serial.print(", control=");
  77. Serial.print(control);
  78. Serial.print(", value=");
  79. Serial.print(value);
  80. Serial.println();
  81. }