Arduino入門

2. デバイス&サンプル

5. 拡張モジュール&サンプル

アクセサリー

6. アプリケーション

CoreP4X Display 表示

CoreP4X の画面に関する API とサンプルプログラムです。

説明
CoreP4X は画面ドライバーとして M5GFX ライブラリを使用します。簡単な表示は以下の API とサンプルを参照してください。その他の表示 API については、M5GFX ドキュメントを参照してください。

サンプルプログラム

コンパイル要件

  • M5Stack ボードマネージャーバージョン >= 3.3.10-a
  • ボード選択 = M5CoreP4X
  • M5Unified ライブラリバージョン >= 0.3.1
  • M5GFX ライブラリバージョン >= 0.3.1

画面のリセットは M5IOE1 IO11、バックライトは M5IOE1 IO9/PWM1、表示電源は M5IOE1 IO10、タッチのリセットは M5IOE1 IO8 で制御されます。電源投入後、M5Unified がパネルの初期化と電源の有効化を自動的に行います。

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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#include <M5Unified.h>

M5Canvas canvas(&M5.Display);

static void drawBorder()
{
  const int screenW = M5.Display.width();
  const int screenH = M5.Display.height();

  canvas.drawRect(0, 0, screenW, screenH, TFT_BLACK);
  canvas.drawRect(4, 4, screenW - 8, screenH - 8, TFT_BLACK);
  canvas.drawRect(8, 8, screenW - 16, screenH - 16, TFT_BLACK);
}

static void drawMainDemo()
{
  const int screenW = M5.Display.width();
  const int centerX = screenW / 2;

  canvas.fillSprite(TFT_WHITE);
  drawBorder();

  canvas.setTextDatum(middle_center);
  canvas.setTextSize(1);

  canvas.setFont(&fonts::FreeSansBold24pt7b);
  canvas.setTextColor(TFT_BLACK);
  canvas.drawString("CORE", centerX, 150);

  canvas.setTextColor(TFT_BLUE);
  canvas.drawString("P4X", centerX, 214);

  canvas.setFont(&fonts::FreeSansBold12pt7b);
  canvas.setTextColor(TFT_BLACK);
  canvas.drawString("Panel: ST7102 + CST3530", centerX, 292);

  char resolutionText[32];
  snprintf(resolutionText, sizeof(resolutionText), "Resolution: %d x %d", screenW, M5.Display.height());
  canvas.setFont(&fonts::FreeSans18pt7b);
  canvas.setTextColor(TFT_BLUE);
  canvas.drawString(resolutionText, centerX, 338);

  canvas.setFont(&fonts::FreeSans12pt7b);
  canvas.setTextColor(TFT_BLACK);
  canvas.drawString("MIPI DSI 2-Lane", centerX, 382);

  const uint16_t colors[] = {
    TFT_RED, TFT_YELLOW, TFT_GREEN, TFT_CYAN, TFT_BLUE, TFT_MAGENTA
  };
  const int barX = 40;
  const int barY = 420;
  const int barW = screenW - 80;
  const int barH = 36;
  const int cellW = barW / 6;

  for (int i = 0; i < 6; ++i) {
    const int x = barX + i * cellW;
    const int w = (i == 5) ? (barX + barW - x) : cellW;
    canvas.fillRect(x, barY, w, barH, colors[i]);
    canvas.drawRect(x, barY, w, barH, TFT_BLACK);
  }

  canvas.pushSprite(0, 0);
}

void setup()
{
  auto cfg = M5.config();
  cfg.serial_baudrate = 115200;
  M5.begin(cfg);

  M5.Display.setRotation(0);
  M5.Display.setBrightness(160);
  canvas.createSprite(M5.Display.width(), M5.Display.height());
  drawMainDemo();

  Serial.printf("display: %d x %d\n", M5.Display.width(), M5.Display.height());
}

void loop()
{
  M5.update();
  delay(100);
}

書き込み後、画面には白背景で CoreP4X の製品名、ST7102 パネル情報、480 x 480 の解像度、MIPI DSI インターフェースの説明、下部に 6 色のテストバーが表示されます。

Page Tools
PDF
On This Page