LoginSignup
0
1

More than 3 years have passed since last update.

[ネタ]iPhone Xに物理ホームボタンを追加する[ネタ]

Posted at

最近のiPhoneって、ホームボタンないんですってね。
ホームボタンあったら、嬉しいですよね?
Android使いなのでよくしらないですが。

ESP32を使って物理ボタンを追加しましょう。

仕組み

ArduionoのライブラリーでBluetoothキーボードにできるものがあったので、これを使います。

ESP32-BLE-Keyboard
https://github.com/T-vK/ESP32-BLE-Keyboard

準備するもの

ESP32-DevKitC V4
ブレッドボード
タクトスイッチ

こんな感じです。

IMG_20200430_161245.jpg

ソース

タクトスイッチが押されたらcommand + Hを送ります。それだけです。

#include <Arduino.h>
#include <BleKeyboard.h>

BleKeyboard bleKeyboard;

const int switchPin = 32;

int currentState = 0;
int beforeState = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(switchPin, INPUT);

  bleKeyboard.begin();
}

boolean isChange(int current, int before)
{
  return (current != before) && (current == 1);
}

void loop()
{
  currentState = digitalRead(switchPin);

  if (isChange(currentState, beforeState))
  {
    Serial.println("Change!!!");

    if(bleKeyboard.isConnected()) {
      bleKeyboard.press(KEY_LEFT_GUI);  // Windows key
      bleKeyboard.press(0x68);  // H key
      delay(100);
      bleKeyboard.releaseAll();
    }
  }

  beforeState = currentState;

  delay(100);
}

使ってみた

手元にあるiPadで試してみました。
Bluetoothの設定にてESP32 BLE Keyboardとペアリングをすれば準備完了。

タクトスイッを押せばホーム画面に戻ります!期待通り!

ただし!物理キーボードが接続されていると判定されるので、テキスト入力が必要なところでソフトウェアキーボードが出ません!!!

どうしても使いたい場合は、下向き三角(下図)を長押しするとソフトウェアキーボードが出てくれます。一度ソフトウェアキーボードが出る状態になると、次からもソフトウェアキーボードが出ます!

コメント 2020-04-30 160915.png

やった! これで、物理ホームボタンの完成です!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1