1. #include <HID.h>
    2. static const uint8_t _hidReportDescriptor[] PROGMEM = {
    3. 0x05, 0x0c, // USAGE_PAGE (Consumer Page)
    4. 0x09, 0x01, // USAGE (Consumer Control)
    5. 0xa1, 0x01, // COLLECTION (Application)
    6. 0x85, 0x05, // REPORT_ID (5)
    7. 0x15, 0x00, // Logical Minimum (0)
    8. 0x25, 0x01, // Logical Maximum (1)
    9. 0x09, 0xea, // USAGE (Volume Decrement)
    10. 0x09, 0xe9, // USAGE (Volume Increment)
    11. 0x09, 0xe2, // USAGE (Mute)
    12. 0x09, 0xcd, // USAGE (Play/Pause)
    13. 0x0a, 0x83, 0x01, //USAGE (Windows Media Player(0x183))
    14. 0x0a, 0x23, 0x02, //USAGE (AC Home(0x0223))
    15. 0x0a, 0x92, 0x01, //USAGE (AL Calculator(0x192))
    16. 0x15, 0x00, // LOGICAL_MINIMUM (0)
    17. 0x25, 0x01, // LOGICAL_MAXIMUM (1)
    18. 0x95, 0x07, // REPORT_COUNT (7)
    19. 0x75, 0x01, // REPORT_SIZE (1)
    20. 0x81, 0x02, // INPUT (Data,Var,Abs)
    21. 0x75, 0x01, // REPORT_SIZE (1)
    22. 0x95, 0x01, // REPORT_COUNT (1)
    23. 0x81, 0x03, // INPUT (Cnst,Var,Abs)
    24. 0xc0 // END_COLLECTION
    25. };
    26. //八位数据 每位的功能为
    27. // 0 Volume Decrement
    28. // 1 Volume Increment
    29. // 3 Mute
    30. // 4 Play/Pause
    31. // 5 Windows Media Player(0x183)
    32. // 6 AC Home(0x0223)
    33. // 7 AL Calculator(0x192)
    34. // 8
    35. uint8_t report[1];
    36. void setup()
    37. {
    38. // put your setup code here, to run once:
    39. static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor));
    40. HID().AppendDescriptor(&node);
    41. pinMode(4, INPUT);
    42. Serial.begin(9600);
    43. report[0] = 0x01;
    44. }
    45. void loop()
    46. {
    47. report[0] = 0x01;
    48. HID().SendReport(5,report,1);//(data,len)
    49. delay(100);
    50. }