pdf-icon

Arduino入門

2. デバイス&サンプル

Air Quality Display 画面表示

Air Qualityは画面ドライバとしてM5GFXライブラリを使用します。簡単な表示を実現するには以下のAPI&サンプルを参照してください。詳細なAPIはM5GFXのソースを参照してください。

サンプルプログラム

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include <M5Unified.h>

// Function to draw a random rectangle
void draw_function(LovyanGFX* gfx) {
    int x      = rand() % gfx->width();
    int y      = rand() % gfx->height();
    int r      = (gfx->width() >> 4) + 2;
    uint16_t c = rand();
    gfx->fillRect(x - r, y - r, r * 2, r * 2, c);
}

void setup() {
    // Initialize M5Unified
    auto cfg = M5.config();
    M5.begin(cfg);  

    // Set text size based on screen height
    int textsize = M5.Display.height() / 60;
    if (textsize == 0) {
        textsize = 1;
    }
    M5.Display.setTextSize(textsize);
}

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 = rand();
    M5.Display.fillCircle(x, y, r, c);

    // Call draw_function to draw a random rectangle
    draw_function(&M5.Display);

    delay(50);
}

アップロード後、以下のようになります:

On This Page