Last active
April 18, 2023 00:36
-
-
Save 3110/e72be684db037d974c777b5929f3d04b to your computer and use it in GitHub Desktop.
ATOM Liteでスクリーンセーバーを起動しないようにする(BLEマウス版)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ATOM Lite を BLE マウスにして,定期的にマウスカーソルを | |
動かすことでスクリーンセーバーを起動しないようにする。 | |
https://github.com/T-vK/ESP32-BLE-Mouse を Arduino IDE に | |
インストールしておくこと。 | |
1. ATOM Liteにプログラムを書き込む。 | |
2. プログラムを起動する。 | |
3. ATOM Lite BLE Mouseとペアリングする。 | |
4. ボタンを押すとLEDが青く光ってスクリーンセーバーを起動させない | |
モードを開始する。 | |
LEDが赤く光る場合はマウスとして接続できていない。 | |
5. スクリーンセーバを起動させないためにマウスを動かすときはLEDが | |
0.1秒だけ黄色に光る | |
6. LEDが青色に光っているときにボタンを押すと,スクリーンセーバーを | |
起動させないモードが終了する。 | |
7. もう一度ボタンを押すと 4 に戻る。 | |
*/ | |
#include <M5Atom.h> | |
#include <BleMouse.h> // https://github.com/T-vK/ESP32-BLE-Mouse | |
#include <utility/M5Timer.h> | |
const long KILL_TIME_SEC = 30; | |
const CRGB CRGB_KILLER_MODE_ON(0x00, 0x00, 0xf0); | |
const CRGB CRGB_KILLER_MODE_OFF(0x00, 0x00, 0x00); | |
const CRGB CRGB_KILLED(0xf0, 0xf0, 0x00); | |
// 数値は緑だが Lite では赤く光る https://github.com/m5stack/M5Atom/issues/5 | |
const CRGB CRGB_KILLER_MODE_ERROR(0x00, 0xf0, 0x00); | |
const std::string DEVICE_NAME("ATOM Lite BLE Mouse"); | |
const std::string DEVICE_MANUFACTURER("M5Stack"); | |
BleMouse mouse(DEVICE_NAME, DEVICE_MANUFACTURER); | |
M5Timer killTimer; | |
bool enableKiller = false; | |
bool isEmitKiller = false; | |
void emitKiller() { | |
isEmitKiller = true; | |
} | |
void setup() { | |
M5.begin(true, false, true); | |
mouse.begin(); | |
killTimer.setInterval(KILL_TIME_SEC * 1000, emitKiller); | |
Serial.println("Screen Saver Killer started"); | |
} | |
void loop() { | |
killTimer.run(); | |
if (M5.Btn.wasPressed()) { | |
enableKiller = !enableKiller; | |
Serial.print("Enable Killer: "); | |
Serial.println(enableKiller ? "True" : "False"); | |
} | |
if (enableKiller) { | |
if (mouse.isConnected()) { | |
M5.dis.drawpix(0, CRGB_KILLER_MODE_ON); | |
if (isEmitKiller) { | |
isEmitKiller = false; | |
mouse.move(1, 0, 0); | |
mouse.move(-1, 0, 0); | |
M5.dis.drawpix(0, CRGB_KILLED); | |
delay(100); | |
M5.dis.drawpix(0, CRGB_KILLER_MODE_ON); | |
Serial.println("Killed"); | |
} | |
} else { | |
M5.dis.drawpix(0, CRGB_KILLER_MODE_ERROR); | |
} | |
} else { | |
M5.dis.drawpix(0, CRGB_KILLER_MODE_OFF); | |
} | |
delay(100); | |
M5.update(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment