2015-01-02 15:59:33 +00:00
|
|
|
/*
|
2015-08-09 12:39:42 +00:00
|
|
|
Copyright (c) 2014-2015 NicoHood
|
2015-01-02 15:59:33 +00:00
|
|
|
See the readme for credit to other people.
|
|
|
|
|
|
|
|
|
|
System example
|
|
|
|
|
Press a button to put pc into sleep/shut it down or wake it up again.
|
2015-08-09 12:39:42 +00:00
|
|
|
|
|
|
|
|
See HID Project documentation for more Consumer keys.
|
2015-04-11 07:31:23 +00:00
|
|
|
https://github.com/NicoHood/HID/wiki/System-API
|
2015-01-02 15:59:33 +00:00
|
|
|
*/
|
|
|
|
|
|
2015-08-09 12:39:42 +00:00
|
|
|
#include "HID.h"
|
2015-08-24 15:05:20 +00:00
|
|
|
#include "HID-Project.h"
|
2015-08-09 12:39:42 +00:00
|
|
|
|
2015-01-02 15:59:33 +00:00
|
|
|
const int pinLed = LED_BUILTIN;
|
|
|
|
|
const int pinButtonS = 2;
|
|
|
|
|
const int pinButtonW = 3;
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
// prepare led + buttons
|
|
|
|
|
pinMode(pinLed, OUTPUT);
|
|
|
|
|
pinMode(pinButtonS, INPUT_PULLUP);
|
|
|
|
|
pinMode(pinButtonW, INPUT_PULLUP);
|
|
|
|
|
|
|
|
|
|
// Sends a clean report to the host. This is important on any Arduino type.
|
|
|
|
|
System.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
if (!digitalRead(pinButtonS)) {
|
|
|
|
|
digitalWrite(pinLed, HIGH);
|
|
|
|
|
|
2015-08-09 12:39:42 +00:00
|
|
|
// Puts pc into sleep mode/shuts it down
|
2015-01-02 15:59:33 +00:00
|
|
|
System.write(SYSTEM_SLEEP);
|
|
|
|
|
//System.write(SYSTEM_POWER_DOWN);
|
|
|
|
|
|
2015-08-09 12:39:42 +00:00
|
|
|
// Simple debounce
|
2015-01-02 15:59:33 +00:00
|
|
|
delay(300);
|
|
|
|
|
digitalWrite(pinLed, LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!digitalRead(pinButtonW)) {
|
|
|
|
|
digitalWrite(pinLed, HIGH);
|
|
|
|
|
|
2015-08-09 12:39:42 +00:00
|
|
|
// Tries to wake up the PC
|
|
|
|
|
// This might fail on some PCs/Laptops where USB wakeup is not supported
|
2015-02-28 09:42:41 +00:00
|
|
|
System.write(SYSTEM_WAKE_UP);
|
2015-01-02 15:59:33 +00:00
|
|
|
|
2015-08-09 12:39:42 +00:00
|
|
|
// Simple debounce
|
2015-01-02 15:59:33 +00:00
|
|
|
delay(300);
|
|
|
|
|
digitalWrite(pinLed, LOW);
|
|
|
|
|
}
|
2015-04-11 07:31:23 +00:00
|
|
|
}
|