みかづきブログ・カスタム

基本的にはちょちょいのほいです。

M5Stack CoreS3-SEでUnit Glass2を制御する 📺

docs.m5stack.com
docs.m5stack.com

Unit Glass2のページの最下部に、

"Unit Glass2" & "CoreS3" Grove Port Connection Note:
Please modify the example program according to the actual PIN number when using.
Available Ports: PORT.A PORT.B PORT.C .

と書いてある通り、glass2を初期化する際に、2と1を渡す必要があります。

ソースコード

#include <M5Unified.h>
#include <M5UnitGLASS2.h>

// M5UnitGLASS2 glass2; // Core2
M5UnitGLASS2 glass2(2, 1, 400000); // CoreS3
LGFX_Sprite sprite(&glass2);

int screenWidth;
int screenHeight;
int dotSize = 10;
int x = 0;

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

  M5.begin(cfg);

  glass2.begin();

  screenWidth = glass2.width();
  screenHeight = glass2.height();

  sprite.createSprite(screenWidth, screenHeight);
  sprite.fillScreen(TFT_BLACK);
}

void loop() {
  M5.update();

  sprite.fillRect(
    0,
    0,
    screenWidth,
    screenHeight,
    TFT_BLACK
  );

  sprite.fillRect(
    x - dotSize,
    (int)((screenHeight - dotSize) / 2),
    dotSize,
    dotSize,
    TFT_WHITE
  );

  x = (int)((x + 1) % (screenWidth + dotSize));

  sprite.pushSprite(0, 0);
  delay(10);
}

DEMO

GIFアニメだと点滅しているように見えますが、実際には綺麗に動いています。