Google Meet用ミュートON/OFFワンボタンBLEキーボード
Google Meetで会話中にミュートON/OFFできるワンボタンBLEキーボードつくったよ。キー押し下げでCtrl+Dを入力するだけのキーボードです。
https://youtu.be/TQVkMWxuSAs
いるもの
nRF52840が入ったボードならなんでもok
キートップは付属していないので適当に入手してください。
ヘッダ&ソケット
ハードウェア
1. キースイッチとピンヘッダを専用ボードにはんだづけ。
2. Pro nRF52840 Miniにピンソケットをはんだづけ。
3. Pro nRF52840 Miniのピン30→専用ボードのピン1、ピン31→専用ボードのピン2になるように接続。
スケッチ
このスケッチのビルドにはnRF52840用のボードパッケージが必要です。下記リンクを参考にArduion IDEにボードパッケージを追加し、ツール>ボード:Nordic nRF52840DK (PCA10056)を選んでビルド&書き込みしてください。書き込みが終わったらパソコンとペアリングして使ってください。
code:mute_sw.ino
BLEDis bledis;
BLEHidAdafruit blehid;
int lastPinState = 1;
void setup()
{
pinMode(PIN_SW_1, INPUT_PULLUP);
pinMode(PIN_SW_2, OUTPUT);
digitalWrite(PIN_SW_2, LOW);
pinMode(PIN_LED, OUTPUT);
digitalWrite(PIN_LED, LOW);
Bluefruit.begin();
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
Bluefruit.setName("BLE Ctrl+D Keyboard");
// Configure and start DIS (Device Information Service)
bledis.setManufacturer("Make Anything Industries");
bledis.setModel("BLE Ctrl+D Keyboard");
bledis.begin();
/* Start BLE HID
* Note: Apple requires BLE devices to have a min connection interval >= 20m
* (The smaller the connection interval the faster we can send data).
* However, for HID and MIDI device Apple will accept a min connection
* interval as low as 11.25 ms. Therefore BLEHidAdafruit::begin() will try to
* set the min and max connection interval to 11.25 ms and 15 ms respectively
* for the best performance.
*/
blehid.begin();
/* Set connection interval (min, max) to your perferred value.
* Note: It is already set by BLEHidAdafruit::begin() to 11.25ms - 15ms
* min = 9*1.25=11.25 ms, max = 12*1.25= 15 ms
*/
/* Bluefruit.Periph.setConnInterval(9, 12); */
// Set up and start advertising
startAdv();
}
void startAdv(void)
{
// Advertising packet
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();
Bluefruit.Advertising.addAppearance(BLE_APPEARANCE_HID_KEYBOARD);
// Include BLE HID service
Bluefruit.Advertising.addService(blehid);
// There is enough room for the dev name in the advertising packet
Bluefruit.Advertising.addName();
/* Start Advertising
* - Enable auto advertising if disconnected
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
* - Timeout for fast mode is 30 seconds
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
*
* For recommended advertising interval
*/
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(80, 1600); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
}
void loop()
{
int pinState = digitalRead(PIN_SW_1);
if (pinState != lastPinState)
{
// Make sure we are connected and bonded/paired
for (uint16_t conn_hdl = 0; conn_hdl < BLE_MAX_CONNECTION; conn_hdl++)
{
BLEConnection *connection = Bluefruit.Connection(conn_hdl);
if (connection && connection->connected() && connection->paired())
{
if (pinState == 0)
{
// Turn on red LED when we start sending data
digitalWrite(PIN_LED, HIGH);
// Send 'Ctrl+D' key press to the peer
uint8_t modifier = KEYBOARD_MODIFIER_LEFTCTRL;
uint8_t keycode6 = {HID_KEY_D, 0, 0, 0, 0, 0}; blehid.keyboardReport(modifier, keycode);
}
else
{
// Turn off the red LED
digitalWrite(PIN_LED, LOW);
// Send key release
blehid.keyRelease();
}
}
}
lastPinState = pinState;
}
// Delay to avoid constant capturing
delay(16);
}