
Arduino Quick Start
Chain Captain display related APIs and sample programs.
3.3.10-aM5ChainCaptain0.3.00.3.0The LCD reset is controlled by M5IOE1 IO1, the backlight by M5IOE1 IO11, and the display power by M5IOE1 IO12. After power-on, M5Unified performs panel initialization and enables the power automatically.
#include <M5Unified.h>
static int ballX = 28;
static int ballY = 100;
static int dirX = 5;
static int dirY = 4;
void setup()
{
delay(500);
auto cfg = M5.config();
cfg.serial_baudrate = 115200;
M5.begin(cfg);
M5.Display.setRotation(0);
M5.Display.setBrightness(128);
M5.Display.fillScreen(TFT_BLACK);
M5.Display.setTextDatum(middle_center);
M5.Display.setFont(&fonts::FreeSansBold12pt7b);
M5.Display.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Display.drawString("Chain Captain", 120, 20);
}
void loop()
{
// Bounce inside the drawing area.
ballX += dirX;
ballY += dirY;
if (ballX < 12 || ballX > 228) {
dirX = -dirX;
ballX += dirX * 2;
}
if (ballY < 52 || ballY > 228) {
dirY = -dirY;
ballY += dirY * 2;
}
const uint16_t color = M5.Display.color565(ballX, 255 - ballY, 180);
// Batch drawing to avoid flicker.
M5.Display.startWrite();
M5.Display.fillRect(8, 48, 224, 184, TFT_BLACK);
M5.Display.drawRect(8, 48, 224, 184, TFT_DARKGREY);
M5.Display.fillCircle(ballX, ballY, 10, color);
M5.Display.endWrite();
delay(20);
}After uploading, the device name is shown at the top of the screen, and a colored ball with a bounce effect is displayed below.
