* Serial as a #define * Typo * fixes USBCDC declaration * Fixes Examples * simplifies examples * Adds USB Serial Events * adds error msg when ESP32 is used with USB
29 lines
738 B
C++
29 lines
738 B
C++
#ifndef ARDUINO_USB_MODE
|
|
#error This ESP32 SoC has no Native USB interface
|
|
#elif ARDUINO_USB_MODE == 1
|
|
#warning This sketch should be used when USB is in OTG mode
|
|
void setup(){}
|
|
void loop(){}
|
|
#else
|
|
#include "USB.h"
|
|
#include "USBHIDConsumerControl.h"
|
|
USBHIDConsumerControl ConsumerControl;
|
|
|
|
const int buttonPin = 0;
|
|
int previousButtonState = HIGH;
|
|
|
|
void setup() {
|
|
pinMode(buttonPin, INPUT_PULLUP);
|
|
ConsumerControl.begin();
|
|
USB.begin();
|
|
}
|
|
|
|
void loop() {
|
|
int buttonState = digitalRead(buttonPin);
|
|
if ((buttonState != previousButtonState) && (buttonState == LOW)) {
|
|
ConsumerControl.press(CONSUMER_CONTROL_VOLUME_INCREMENT);
|
|
ConsumerControl.release();
|
|
}
|
|
previousButtonState = buttonState;
|
|
}
|
|
#endif /* ARDUINO_USB_MODE */
|