stress free Blutooth Keyboard for scroll only
									midjuorney が面白くて、discordでずっと見ている。
そこで若干ストレスなのは、スクロール操作。
マウスのホイールでグリグリするのも、ずっとだと疲れる。
ということで、タッチセンサーの PageDown キーを作ってみた。
以前、Macをスリープさせるために作ったのの応用。
結果、ふれるだけの操作は快適。
タッチセンサーは、ダブルクリックなど素早い操作には向かないが、楽々。
パーツ
Aliexpress で購入したタッチセンサー。
VCC,GND,OUTの3線で、タッチでON/OFFモードと、タッチ時のみONモードの2つがある。
切り換えは、基板上のチップのハンダで溶かして除くという大ざっぱさがいい。
ONのときは、光るのでちょっとかっこいい。
購入した商品はもうないけど、AliExpress でこんなキーワード探せばある。
Capacitive touch switch button module
Bluetoothキーボードには、M5Atomを利用
数年前は1000円くらいだったけど、今は1400円くらい。
電子部品はコロナのせいか、みんな値上がりしてる。。。
`
#配線
ボタンはのON/OFFは、G21 に配線してみた。
source code
platfrom.ini
; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:m5stack-atom]
platform = espressif32
board = m5stack-atom
framework = arduino
lib_deps = 
    t-vk/ESP32 BLE Keyboard@^0.3.2
    m5stack/M5Atom@^0.1.0
    fastled/FastLED@^3.5.0
main.cpp
#include <Arduino.h>
/**
 * This example turns the ESP32 into a Bluetooth LE keyboard that writes the words, presses Enter, presses a media key and then Ctrl+Alt+Delete
 */
#include <M5Atom.h>
#include <BleKeyboard.h>
BleKeyboard bleKeyboard("PgDownKeyboard");
void setup()
{
  Serial.begin(9600);
  M5.begin(true, false, true);
  M5.dis.drawpix(0, 0xf00000); // init red
  Serial.println("Starting BLE work!");
  delay(20);
  bleKeyboard.begin();
  delay(20);
  pinMode(22, INPUT_PULLDOWN);
}
void loop()
{
  M5.dis.drawpix(0, 0x100000); // dark green
  int status = digitalRead(21);
  if (status)
  {
    M5.dis.drawpix(0, 0x0000f0); // blue
    if (bleKeyboard.isConnected())
    {
      KeyReport keyReport;
      // press
      bleKeyboard.press(KEY_PAGE_DOWN);
      bleKeyboard.release(KEY_PAGE_DOWN);
      delay(100);
      bleKeyboard.releaseAll();
    }
  }
  delay(100);
  M5.dis.drawpix(0, 0x101000); // dark green
  M5.update();
}


            



