
M5 ATOM Lite RGBLEDを点灯させる。
M5Stack Atom Liteで内蔵RGBLEDを制御します。

东莞市欧思科光电科技有限公司SK6812という駆動IC内蔵型LEDが、ATOM Liteに組み込まれています。(回路図赤枠)。
1線式ワイヤなので、パルス幅の大きさで0,1を送信します。
”0”を送信 High:0.3us Low:0.9us
"1"を送信 High:0.6us Low:0.6us

デイジーチェーンでSK6812のDINとDOUTを数珠つなぎに接続すれば、いくらでも、LEDを直列に並べることができます。たとえば、3つのSK6812を接続した場合、8bit×3color×3led=24bits×3led=72bits をシリアル送信することになります。

転送のビットは、G7..G0, R7..R0, B7..B0の順で転送されます。
ライブラリーの使用
今回は、一からプログラムしないで、ライブラリーを使用しました。
開発環境はVScode + PlatformIOで制作しました。まず、
ATOM用にM5ATOM by M5Stackライブラリーを追加しておきます。
次に、
SK6812を駆動するarduinoライブラリーFastLED by by Daniel Garciaをprojectに加えます。


コード全体
/*
**********************************************************************************
M5 ATOM Lite
SK6812 LED グラデーション表示
※using libratries=> M5ATOM, FastLED
**********************************************************************************
*/
#include <M5Atom.h>
/// @brief グローバル変数
uint8_t r,g,b;
/// @brief Atom Lite 初期化
void setup()
{
int i;
// 本体初期化(UART有効, I2C無効, LED有効)
M5.begin(true,false,true);
delay(50);
//LEDを点滅させる。
for(i=0; i<=1; i++)
{
M5.dis.drawpix(0, 0x0000FF);
delay(500);
M5.dis.drawpix(0, 0x000000);
delay(500);
}
r=g=b=0;
}
/// @brief メインループ
void loop()
{
CRGB color;//CRGB構造体
for(r=0; r<0xFF; r++)
{
if(b!=0)b--;
color.setRGB(r,g,b);//CRGBにrgb(8,8,8bits)をセット
M5.dis.drawpix(0,color);//LEDに表示
delay(10);
}
for(g=0; g<0xFF; g++)
{
r--;
color.setRGB(r,g,b);
M5.dis.drawpix(0,color);
delay(10);
}
for(b=0; b<0xFF; b++)
{
g--;
color.setRGB(r,g,b);
M5.dis.drawpix(0,color);
delay(10);
}
}
CRGB構造体(色指定)
SK6812にシリアル転送する関数 M5.dis.drawpix(uint8_t Number, CRGB Color)を使用します。この時にFastLEDライブラリーpixeltypes.hに定義されているCRGB構造体を使用します。
struct CRGB {
union {
struct {
union {
uint8_t r; ///< Red channel value
uint8_t red; ///< @copydoc r
};
union {
uint8_t g; ///< Green channel value
uint8_t green; ///< @copydoc g
};
union {
uint8_t b; ///< Blue channel value
uint8_t blue; ///< @copydoc b
};
};
/// Access the red, green, and blue data as an array.
/// Where:
/// * `raw[0]` is the red value
/// * `raw[1]` is the green value
/// * `raw[2]` is the blue value
uint8_t raw[3];
};
<略>
SK6812データシリアル転送関数
M5.dis.drawpix関数の第一引数numberは、デイジーチェーンでつながれたSK6812の個数だと思われます。ATOM Liteの場合、SK6812は一つだけなので、引数は”0”ということになります。

以上で、RGBLEDをグラデーション表示できるようになると思います。