LoginSignup
1
0

More than 1 year has passed since last update.

M5stick用ジョイスティックでBLEマウスを作成してiPadを操作

Last updated at Posted at 2022-04-03

M5stickCと、ジョイスティックユニットを接続して、bluetoothマウスを作成し、iPadを操作してみました。

M5stickCとジョイスティックユニットをgrove互換ケーブルで接続

IMG-6007.JPG

M5stickCにプログラムをインストール

#include <M5StickCPlus.h>
#include "Wire.h"
#include <BleMouse.h>

#define JOY_ADDR 0x52
BleMouse bleMouse;
double vbat = 0.0;
int8_t bat_charge_p = 0;

void show_battery_info() {
  // バッテリー電圧表示
  // GetVbatData()の戻り値はバッテリー電圧のステップ数で、
  // AXP192のデータシートによると1ステップは1.1mV
  vbat = M5.Axp.GetVbatData() * 1.1 / 1000;
  // バッテリー残量表示
  // 簡易的に、線形で4.2Vで100%、3.0Vで0%とする
  bat_charge_p = int8_t((vbat - 3.0) / 1.2 * 100);
  if (bat_charge_p > 100) {
    bat_charge_p = 100;
  } else if (bat_charge_p < 0) {
    bat_charge_p = 0;
  }
  M5.Lcd.setCursor(45, 2, 1);
  M5.Lcd.printf("Charge: %3d%%", bat_charge_p);
}

void setup() {
  M5.begin();
  //M5.Lcd.clear();
  //disable the speak noise
  //dacWrite(25, 0);
  bleMouse.begin();
  Wire.begin(32, 33, 100000);
  M5.Lcd.setRotation(1);
}
uint8_t x_data;
uint8_t y_data;
uint8_t button_data;
char data[100];
int cnt = 1;

void loop() {
  M5.update();
// ボタンBでパワーオフ
  if ( M5.BtnB.wasPressed() ) {
    M5.Axp.PowerOff();
  }

//ボタンAで画面表示のオンオフ
  if (M5.BtnA.wasPressed())
  {
    cnt++;
    if (cnt % 2 == 0) {
      M5.Axp.ScreenBreath(0);
    } else {
      M5.Axp.ScreenBreath( 10 );
    }
  }
  show_battery_info();

  Wire.requestFrom(JOY_ADDR, 3);
  if (Wire.available()) {
    x_data = Wire.read();
    y_data = Wire.read();
    button_data = Wire.read();
    sprintf(data, "x:%d y:%d button:%d\n", x_data, y_data, button_data);
    Serial.print(data);
    M5.Lcd.setCursor(1, 30, 2);
    M5.Lcd.printf("x:%04d y:%04d button:%d\n", x_data, y_data, button_data);
    if (x_data < 110) {
      bleMouse.move(4, 0);
      delay(10);
    }
    if (x_data > 135) {
      bleMouse.move(-4, 0);
      delay(10);
    }
    if (y_data > 135) {
      bleMouse.move(0, 4);
      delay(10);
    }
    if (y_data < 110) {
      bleMouse.move(0, -4);
      delay(10);
    }
    if (button_data == 1) {
      bleMouse.click(MOUSE_LEFT);
      delay(1000);
    }

    delay(10);
  }
}

ジョイスティックマウスとiPadは、bluetooth接続できるので便利です。

もちろん、このマウスは、PCでも使えます。

何らかの障害があって普通のマウスが使えない場合に、このようなジョイスティックマウスを使えば、操作できるかどうか試してみることができると思います。

市販のジョイスティックマウスより安価で試せると思います。

ジョイスティックを押し込む操作が難しい場合には、iPad側のアクセシビリティの設定で、滞留コントロールをオンにすれば、クリック操作は自動で行ってくれますので、試してみてください。

1
0
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
1
0