pdf-icon

Arduino入門

2. デバイス&サンプル

6. アプリケーション

Fire RGB LED

Fire RGB LED に関連する API とサンプルプログラムです。

サンプルプログラム

コンパイル要件

  • M5Stack ボードマネージャーバージョン >= 3.2.2
  • ボードオプション = M5Fire
  • M5Unified ライブラリバージョン >= 0.2.8
  • M5GFX ライブラリバージョン >= 0.2.11
  • Adafruit NeoPixel ライブラリバージョン >= 1.15.1
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#include <M5Unified.h>
#include <Adafruit_NeoPixel.h>

#define LED_PIN 15
#define NUM_LEDS 10

Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  auto cfg = M5.config();
  M5.begin(cfg);
  M5.Display.setTextDatum(middle_center);
  M5.Display.setTextFont(&fonts::Orbitron_Light_24);
  M5.Display.setTextSize(1);
  M5.Display.drawString("RGB LED Test", M5.Display.width() / 2, M5.Display.height() / 2);
  strip.begin();
  strip.show();
}

void loop() {
  // Red
  for (char i = 0; i <= NUM_LEDS; i++) { strip.setPixelColor(i, strip.Color(255, 0, 0)); }
  strip.show();
  delay(500);

  // Green
  for (char i = 0; i <= NUM_LEDS; i++) { strip.setPixelColor(i, strip.Color(0, 255, 0)); }
  strip.show();
  delay(500);

  // Blue
  for (char i = 0; i <= NUM_LEDS; i++) { strip.setPixelColor(i, strip.Color(0, 0, 255)); }
  strip.show();
  delay(500);

  // Yellow
  for (char i = 0; i <= NUM_LEDS; i++) { strip.setPixelColor(i, strip.Color(255, 255, 0)); }
  strip.show();
  delay(500);

  // Magenta
  for (char i = 0; i <= NUM_LEDS; i++) { strip.setPixelColor(i, strip.Color(255, 0, 255)); }
  strip.show();
  delay(500);

  // Cyan
  for (char i = 0; i <= NUM_LEDS; i++) { strip.setPixelColor(i, strip.Color(0, 255, 255)); }
  strip.show();
  delay(500);

  // White (all on)
  for (char i = 0; i <= NUM_LEDS; i++) { strip.setPixelColor(i, strip.Color(255, 255, 255)); }
  strip.show();
  delay(500);

  // Black (all off)
  for (char i = 0; i <= NUM_LEDS; i++) { strip.setPixelColor(i, strip.Color(0, 0, 0)); }
  strip.show();
  delay(500);
}

実行結果:

API

Fire RGB LED は Adafruit NeoPixel ライブラリを使用しています。さらに関連する API については、以下のドキュメントを参照してください:

On This Page