pdf-icon

Arduino入門

2. デバイス&サンプル

5. 拡張モジュール&サンプル

アクセサリー

6. アプリケーション

StackChan RGB LED

サンプルプログラム

コンパイル要件

  • M5Stack ボードマネージャーバージョン >= 3.2.2
  • 開発ボード選択 = M5CoreS3
  • M5StackChan ライブラリバージョン >= 1.0.0
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
#include <M5StackChan.h>

struct Color_t {
    uint8_t r = 0;
    uint8_t g = 0;
    uint8_t b = 0;
};

static std::vector<Color_t> colors = {
    {0, 0, 0}, {168, 0, 0}, {0, 168, 0}, {0, 0, 168}, {168, 168, 0}, {168, 0, 168}, {0, 168, 168}, {168, 168, 168},
};

void setup()
{
    /* Init StackChan */
    M5StackChan.begin();
}

void loop()
{
    /* There are 12 RGB LEDs, index 0-5 are on the left, 6-11 are on the right */
    for (int color_index = 0; color_index < colors.size(); color_index++) {
        for (int led_index = 0; led_index < 12; led_index++) {
            M5StackChan.setRgbColor(led_index, colors[color_index].r, colors[color_index].g, colors[color_index].b);
            M5StackChan.refreshRgb();
            delay(1000 / 24);
        }
    }
}

このプログラムは StackChan 上の 12 個の RGB LED を順番に点灯させ、各 LED が黒、赤、緑、青、黄、マゼンタ、シアン、白の色を順番に切り替えます。

On This Page