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.

79 lines
1.5KB

  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(press);
  18. keyboard2.attachPress(press);
  19. midi1.setHandleNoteOff(OnNoteOff);
  20. midi1.setHandleNoteOn(OnNoteOn);
  21. midi1.setHandleControlChange(OnControlChange);
  22. }
  23. void loop()
  24. {
  25. myusb.Task();
  26. midi1.read();
  27. }
  28. void press(int key)
  29. {
  30. Serial.print("key ");
  31. Serial.println(key);
  32. //Serial.print("key ");
  33. //Serial.print((char)keyboard1.getKey());
  34. //Serial.print(" ");
  35. //Serial.print((char)keyboard2.getKey());
  36. //Serial.println();
  37. }
  38. void OnNoteOn(byte channel, byte note, byte velocity)
  39. {
  40. Serial.print("Note On, ch=");
  41. Serial.print(channel);
  42. Serial.print(", note=");
  43. Serial.print(note);
  44. Serial.print(", velocity=");
  45. Serial.print(velocity);
  46. Serial.println();
  47. }
  48. void OnNoteOff(byte channel, byte note, byte velocity)
  49. {
  50. Serial.print("Note Off, ch=");
  51. Serial.print(channel);
  52. Serial.print(", note=");
  53. Serial.print(note);
  54. //Serial.print(", velocity=");
  55. //Serial.print(velocity);
  56. Serial.println();
  57. }
  58. void OnControlChange(byte channel, byte control, byte value)
  59. {
  60. Serial.print("Control Change, ch=");
  61. Serial.print(channel);
  62. Serial.print(", control=");
  63. Serial.print(control);
  64. Serial.print(", value=");
  65. Serial.print(value);
  66. Serial.println();
  67. }