mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-01 04:50:58 +02:00
22 lines
489 B
Arduino
22 lines
489 B
Arduino
![]() |
#include "USB.h"
|
||
|
#include "USBHIDSystemControl.h"
|
||
|
USBHIDSystemControl SystemControl;
|
||
|
|
||
|
const int buttonPin = 0;
|
||
|
int previousButtonState = HIGH;
|
||
|
|
||
|
void setup() {
|
||
|
pinMode(buttonPin, INPUT_PULLUP);
|
||
|
SystemControl.begin();
|
||
|
USB.begin();
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
int buttonState = digitalRead(buttonPin);
|
||
|
if ((buttonState != previousButtonState) && (buttonState == LOW)) {
|
||
|
SystemControl.press(SYSTEM_CONTROL_POWER_OFF);
|
||
|
SystemControl.release();
|
||
|
}
|
||
|
previousButtonState = buttonState;
|
||
|
}
|