
Arduino Quick Start
3.3.10-aM5CoreMatrix0.2.290.2.36The power for the 16 x 16 white LED matrix is controlled by M5IOE1 IO4 / PYB_LEDS_EN. M5GFX turns on the matrix power automatically during initialization.
#include <M5Unified.h>
static constexpr int kSquareSize = 2;
static constexpr int kMinX = 1;
static constexpr int kMaxX = 13;
static int squareX = kMinX;
static int direction = 1;
static bool reachedRight = false;
static void drawFrame()
{
M5.Display.startWrite();
M5.Display.fillScreen(TFT_BLACK);
M5.Display.drawRect(0, 0, 16, 16, TFT_WHITE);
M5.Display.fillRect(squareX, 7, kSquareSize, kSquareSize, TFT_WHITE);
M5.Display.endWrite();
M5.Display.display();
}
static void drawOk()
{
M5.Display.startWrite();
M5.Display.fillScreen(TFT_BLACK);
M5.Display.drawRect(0, 0, 16, 16, TFT_WHITE);
M5.Display.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Display.setTextDatum(textdatum_t::middle_center);
M5.Display.drawString("OK", 8, 8);
M5.Display.endWrite();
M5.Display.display();
}
void setup()
{
auto cfg = M5.config();
cfg.serial_baudrate = 115200;
M5.begin(cfg);
M5.Display.setColorDepth(8);
M5.Display.setRotation(1);
M5.Display.setBrightness(128);
Serial.printf("CoreMatrix display: %d x %d\n",
static_cast<int>(M5.Display.width()),
static_cast<int>(M5.Display.height()));
drawFrame();
}
void loop()
{
squareX += direction;
if (squareX >= kMaxX) {
squareX = kMaxX;
direction = -1;
reachedRight = true;
} else if (squareX <= kMinX) {
squareX = kMinX;
if (reachedRight) {
drawFrame();
delay(200);
drawOk();
delay(1000);
reachedRight = false;
direction = 1;
}
}
drawFrame();
delay(120);
}After uploading, the matrix shows a 16 x 16 border, and a 2 x 2-pixel square moves from left to right inside the border and then back. After completing one round trip, the matrix displays OK, and the square resumes moving.
