pdf-icon

Arduino入門

2. デバイス&サンプル

DinMeter 画面表示

DinMeter は M5GFX ライブラリを画面ドライバとして使用します。以下の API とサンプルを参照することで簡単な表示が可能です。より詳しい API 情報は M5GFX のソースコードをご覧ください。
DinMeter は M5GFX ライブラリを画面ドライバとして使用します。以下の API とサンプルを参照することで簡単な表示が可能です。より詳しい API 情報は M5GFX のソースコードをご覧ください。

サンプルプログラム

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
#include <M5Unified.h>

// Draw a random filled rectangle on any LovyanGFX display
void draw_function(LovyanGFX* gfx) {
  int x = rand() % gfx->width();
  int y = rand() % gfx->height();
  int r = (gfx->width() >> 4) + 2;
  uint16_t c = (uint16_t)rand();
  gfx->fillRect(x - r, y - r, r * 2, r * 2, c);
}

void setup() {
  // Initialize all peripherals (Display, Buttons, etc.)
  auto cfg = M5.config();
  M5.begin(cfg);

  // Seed the RNG
  randomSeed(micros());

  // Compute a sensible text size and clear the screen
  int ts = M5.Display.height() / 60;
  M5.Display.setTextSize(ts > 0 ? ts : 1);
  M5.Display.clear();
}

void loop() {
  // Draw a random filled circle
  int x = rand() % M5.Display.width();
  int y = rand() % M5.Display.height();
  int r = (M5.Display.width() >> 4) + 2;
  uint16_t c = (uint16_t)rand();
  M5.Display.fillCircle(x, y, r, c);

  // Then draw a random filled rectangle
  draw_function(&M5.Display);

  delay(100);
}

アップロード完了後、以下のような効果が確認できます。

On This Page