Skip to content

Instantly share code, notes, and snippets.

@tokyoff
Created September 12, 2019 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokyoff/8d1d595451a08b12ec3f065f7f82aa54 to your computer and use it in GitHub Desktop.
Save tokyoff/8d1d595451a08b12ec3f065f7f82aa54 to your computer and use it in GitHub Desktop.
ポチッと押すだけでシャットダウンができるワンボタンキーボード用ソースコード
//-------------------------------------------------------------
// シャットダウン専用キーボード
// https://www.one-button-key.com/
//
// ※"HID-Project" というライブラリが必要です。
// ※Arduino IDE のライブラリマネージャからインストールできます。
//-------------------------------------------------------------
#include <HID-Project.h>
#define PIN_KEYSW (9)
int prevKeyState;
int currKeyState;
void setup() {
pinMode(PIN_KEYSW, INPUT_PULLUP);
prevKeyState = HIGH;
currKeyState = HIGH;
System.begin();
}
void loop() {
currKeyState = digitalRead(PIN_KEYSW);
// キースイッチが押された
if ((prevKeyState == HIGH) && (currKeyState == LOW)) {
System.write(SYSTEM_POWER_DOWN); // シャットダウン
//System.write(SYSTEM_SLEEP); // スリープ
//System.write(SYSTEM_WAKE_UP); // 起床
}
prevKeyState = currKeyState;
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment