1414/* This sketch demonstrates USB HID mouse
1515 * Press button pin will move
1616 * - mouse toward bottom right of monitor
17- *
17+ *
1818 * Depending on the board, the button pin
1919 * and its active state (when pressed) are different
2020 */
21- #if defined ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS
21+ #if defined ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS || defined ARDUINO_NRF52840_CIRCUITPLAY
2222 const int pin = 4 ; // Left Button
2323 bool activeState = true ;
24- #elif defined ARDUINO_NRF52840_FEATHER
25- const int pin = 7 ; // UserSw
24+
25+ #elif defined PIN_BUTTON1
26+ const int pin = PIN_BUTTON1;
2627 bool activeState = false ;
28+
2729#else
2830 const int pin = 12 ;
2931 bool activeState = false ;
3032#endif
31-
33+
3234
3335// HID report descriptor using TinyUSB's template
3436// Single Report (no ID) descriptor
@@ -51,6 +53,7 @@ void setup()
5153 // Set up button, pullup opposite to active state
5254 pinMode (pin, activeState ? INPUT_PULLDOWN : INPUT_PULLUP);
5355
56+ usb_hid.setBootProtocol (HID_ITF_PROTOCOL_MOUSE);
5457 usb_hid.setPollInterval (2 );
5558 usb_hid.setReportDescriptor (desc_hid_report, sizeof (desc_hid_report));
5659 // usb_hid.setStringDescriptor("TinyUSB Mouse");
@@ -86,7 +89,8 @@ void loop()
8689
8790 if ( usb_hid.ready () )
8891 {
92+ uint8_t const report_id = 0 ; // no ID
8993 int8_t const delta = 5 ;
90- usb_hid.mouseMove (0 , delta, delta); // no ID: right + down
94+ usb_hid.mouseMove (report_id , delta, delta); // right + down
9195 }
9296}
0 commit comments