M5Stamp picoでM5Unifiedを使ってRGB LEDを点灯させる場合にどうするか試す。
ドキュメントによるとRGB LEDはサポートされず、FastLED Libraryを使う様にということの様だ。
色はRGBで指定するが、M5Stamp picoはRとGが逆になっている様なので、setLED内で入れ替えている。
setBrightness()で輝度を指定していて15%で十分だった。100%だと目が眩んでしまう。
#include <Arduino.h>
#include <M5Unified.h>
#include <FastLED.h>
#define LED_PIN 27
#define NUM_LEDS 1
static CRGB leds[NUM_LEDS];
void setLed(CRGB color) {
// change RGB to GRB
uint8_t t = color.r;
color.r = color.g;
color.g = t;
leds[0] = color;
FastLED.show();
}
void setup() {
auto cfg = M5.config();
M5.begin(cfg);
FastLED.addLeds<WS2811, LED_PIN, RGB>(leds, NUM_LEDS);
FastLED.setBrightness(255 * 15 / 100);
}
void loop() {
setLed(CRGB::Red);
delay(1000);
setLed(CRGB::Green);
delay(1000);
setLed(CRGB::Blue);
delay(1000);
setLed(CRGB::Black);
delay(1000);
}