Created
June 17, 2022 20:41
-
-
Save H3wastooshort/cbebb075e93b8453708584444c3de7ba to your computer and use it in GitHub Desktop.
shitty copied together mediakeys buttons thing for an ESP32-S2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Adafruit_TinyUSB.h" | |
#define MUTE_PIN 4 | |
#define V_UP_PIN 7 | |
#define V_DOWN_PIN 8 | |
#define SKIP_PIN 10 | |
#define PREV_PIN 11 | |
#define PP_PIN 12 | |
#define RID_CONSUMER_CONTROL 1 | |
uint8_t const desc_hid_report[] = | |
{ | |
TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(RID_CONSUMER_CONTROL) ) | |
}; | |
// USB HID object. For ESP32 these values cannot be changed after this declaration | |
// desc report, desc len, protocol, interval, use out endpoint | |
Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_NONE, 2, false); | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(MUTE_PIN, INPUT_PULLUP); //Mute | |
pinMode(V_UP_PIN, INPUT_PULLUP); //VUp | |
pinMode(V_DOWN_PIN, INPUT_PULLUP); //VDown | |
pinMode(SKIP_PIN, INPUT_PULLUP); //Skip | |
pinMode(PREV_PIN, INPUT_PULLUP); //Prev | |
pinMode(PP_PIN, INPUT_PULLUP); //PlayPause | |
usb_hid.begin(); | |
while ( !TinyUSBDevice.mounted() ) delay(1); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
delay(10); | |
if (!digitalRead(MUTE_PIN)) { | |
usb_hid.sendReport16(RID_CONSUMER_CONTROL, HID_USAGE_CONSUMER_MUTE); | |
while (!digitalRead(MUTE_PIN)) delay(10); | |
} | |
else if (!digitalRead(V_DOWN_PIN)) { | |
usb_hid.sendReport16(RID_CONSUMER_CONTROL, HID_USAGE_CONSUMER_VOLUME_DECREMENT); | |
while (!digitalRead(V_DOWN_PIN)) delay(10); | |
} | |
else if (!digitalRead(V_UP_PIN)) { | |
usb_hid.sendReport16(RID_CONSUMER_CONTROL, HID_USAGE_CONSUMER_VOLUME_INCREMENT); | |
while (!digitalRead(V_UP_PIN)) delay(10); | |
} | |
else if (!digitalRead(SKIP_PIN)) { | |
usb_hid.sendReport16(RID_CONSUMER_CONTROL, HID_USAGE_CONSUMER_SCAN_NEXT); | |
while (!digitalRead(SKIP_PIN)) delay(10); | |
} | |
else if (!digitalRead(PREV_PIN)) { | |
usb_hid.sendReport16(RID_CONSUMER_CONTROL, HID_USAGE_CONSUMER_SCAN_PREVIOUS); | |
while (!digitalRead(PREV_PIN)) delay(10); | |
} | |
else if (!digitalRead(PP_PIN)) { | |
usb_hid.sendReport16(RID_CONSUMER_CONTROL, HID_USAGE_CONSUMER_PLAY_PAUSE); | |
while (!digitalRead(PP_PIN)) delay(10); | |
} | |
else { | |
usb_hid.sendReport16(RID_CONSUMER_CONTROL, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment