pdf-icon

Arduino入門

2. デバイス&サンプル

Fire RGB LED

M5Fire RGB LED サンプルプログラム。本サンプルはAdafruit NeoPixelライブラリをベースに実装されています。使用前にライブラリマネージャーからAdafruit NeoPixel依存ライブラリをインストールしてください。

サンプルプログラム

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
#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() {
//赤色
for(char i = 0; i <= NUM_LEDS; i++)
{strip.setPixelColor(i, strip.Color(255, 0, 0)); }
strip.show();
delay(1000);
//绿色
for(char i = 0; i <= NUM_LEDS; i++)
{strip.setPixelColor(i, strip.Color(0, 255, 0)); }
strip.show();
delay(1000);
//青色
for(char i = 0; i <= NUM_LEDS; i++)
{strip.setPixelColor(i, strip.Color(0, 0, 255)); }
strip.show();
delay(1000);
}

サンプルプログラムの動作結果は以下のようになります:

On This Page