pdf-icon

Arduino入門

2. デバイス&サンプル

6. アプリケーション

Dial Touch

Dial Touch タッチスクリーンに関連する API とサンプルプログラム。

サンプルプログラム

ビルド要件

  • M5Stack ボードマネージャーバージョン >= 3.2.2
  • ボードオプション = M5Dial
  • M5Dial ライブラリバージョン >= 1.0.3
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <M5Dial.h>

m5::touch_detail_t touchDetail;

void setup() {
  auto cfg = M5.config();
  M5Dial.begin(cfg, false, false);  // encoder, RFID

  M5Dial.Display.setTextColor(GREEN);
  M5Dial.Display.setTextDatum(middle_center);
  M5Dial.Display.setTextFont(&fonts::FreeMono12pt7b);
  M5Dial.Display.setTextSize(1);

  M5Dial.Display.drawString("Touch Test", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2);
}

void loop() {
  M5Dial.update();
  touchDetail = M5Dial.Touch.getDetail();

  if (touchDetail.isPressed()) {
    M5.Display.fillCircle(touchDetail.x, touchDetail.y, 2, SKYBLUE);
  }
}

動作例:

API

M5Dial ライブラリは M5Unified ライブラリを基盤としており、タッチスクリーン部分は M5Unified 内の Touch_Class を利用しています。詳細な API は以下のドキュメントを参照してください:

On This Page