Arduino入門
#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);
}
アップロード完了後、以下のような効果が確認できます。