選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Test.ino 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. keyboard2.attachPress(OnPress);
  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 OnPress(int key)
  29. {
  30. Serial.print("key '");
  31. Serial.print((char)key);
  32. Serial.print("' ");
  33. Serial.println(key);
  34. //Serial.print("key ");
  35. //Serial.print((char)keyboard1.getKey());
  36. //Serial.print(" ");
  37. //Serial.print((char)keyboard2.getKey());
  38. //Serial.println();
  39. }
  40. void OnNoteOn(byte channel, byte note, byte velocity)
  41. {
  42. Serial.print("Note On, ch=");
  43. Serial.print(channel);
  44. Serial.print(", note=");
  45. Serial.print(note);
  46. Serial.print(", velocity=");
  47. Serial.print(velocity);
  48. Serial.println();
  49. }
  50. void OnNoteOff(byte channel, byte note, byte velocity)
  51. {
  52. Serial.print("Note Off, ch=");
  53. Serial.print(channel);
  54. Serial.print(", note=");
  55. Serial.print(note);
  56. //Serial.print(", velocity=");
  57. //Serial.print(velocity);
  58. Serial.println();
  59. }
  60. void OnControlChange(byte channel, byte control, byte value)
  61. {
  62. Serial.print("Control Change, ch=");
  63. Serial.print(channel);
  64. Serial.print(", control=");
  65. Serial.print(control);
  66. Serial.print(", value=");
  67. Serial.print(value);
  68. Serial.println();
  69. }