HID/examples/System/System.ino

49 lines
1.1 KiB
Arduino
Raw Normal View History

2014-06-03 15:10:40 +00:00
/*
Copyright (c) 2014 NicoHood
See the readme for credit to other people.
System example
2014-06-21 22:32:31 +00:00
Press a button to put pc into standby mode
2014-06-03 15:10:40 +00:00
*/
// include HID library
2014-06-03 15:10:40 +00:00
#include <HID.h>
const int pinLed = 13;
const int pinButton = 8;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
// Starts Serial at baud 115200 otherwise HID wont work on Uno/Mega.
// This is not needed for Leonado/(Pro)Micro but make sure to activate desired USB functions in HID.h
Serial.begin(SERIAL_HID_BAUD);
2014-06-03 15:10:40 +00:00
// Sends a clean report to the host. This is important because
// the 16u2 of the Uno/Mega is not turned off while programming
// so you want to start with a clean report to avoid strange bugs after reset.
2014-06-03 15:10:40 +00:00
System.begin();
}
void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
// See list below for more definitions or the official usb documentation
2014-06-05 21:06:36 +00:00
System.write(SYSTEM_SLEEP);
2014-06-03 15:10:40 +00:00
// simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}
/*
Definitions:
SYSTEM_POWER_DOWN
SYSTEM_SLEEP
SYSTEM_WAKE_UP
*/