2026年6月3日水曜日

wioterminal arduino (draft)

 #define LGFX_WIO_TERMINAL

#define LGFX_AUTODETECT
#define LGFX_USE_V1
#include <LovyanGFX.hpp>
#include <LGFX_AUTODETECT.hpp>

static LGFX tft;

void setup() {
  // 液晶の初期化など
  tft.begin();
  digitalWrite(LCD_BACKLIGHT, HIGH);
  tft.setRotation(1);
  tft.fillScreen(TFT_BLACK);
}

void loop() {
  // ランダムな場所に四角形や円、文字列を描画する
  // ランダムな座標
  int x = random(0, 320);
  int y = random(0, 240);
  int r = random(10, 100);

  // ランダムな色
  int red = random(0, 256);
  int green = random(0, 256);
  int blue = random(0, 256);
  int color = tft.color565(red, green, blue);

  switch (random(0, 3)) {
    case 0:
      // 円
      tft.fillCircle(x, y, r, color);
      break;
    case 1:
      // 四角形
      tft.fillRect(x - r, y - r, r * 2, r * 2, color);
      break;
    case 2:
      // 文字列
      tft.setTextDatum(CC_DATUM);
      tft.setTextColor(color);
      tft.drawString("Wio Terminal", x, y);
  }
}