mirror of
https://github.com/m5stack/m5-docs.git
synced 2026-05-20 10:23:01 -07:00
4.3 KiB
4.3 KiB
RGB LED ユニット {docsify-ignore-all}
📝概要 :octocat:サンプルコード 🛒購入リンク 🎬関連動画
概要
**RGB LED**ユニットは帯状にフルカラーLEDが連なったケーブルです。プログラマブルに色や点灯・点滅などをコントロールする事が可能です。Grove インターフェースで接続します。
?> RGB LED Unitには入力側と出力側があります。必ず入力側をM5Core側につないでください。矢印の向きで確認できます。
特徴
関連リンク
サンプルコード
1. Arduino IDE
完全なソースコードはこちら。
/*
Install FastLED library first.
*/
#include <M5Stack.h>
#include "FastLED.h"
#define Neopixel_PIN 21
#define NUM_LEDS 30
CRGB leds[NUM_LEDS];
uint8_t gHue = 0;
static TaskHandle_t FastLEDshowTaskHandle = 0;
static TaskHandle_t userTaskHandle = 0;
void setup(){
Serial.begin(115200);
M5.begin();
M5.Lcd.clear(BLACK);
M5.Lcd.setTextColor(YELLOW); M5.Lcd.setTextSize(2); M5.Lcd.setCursor(40, 0);
M5.Lcd.println("Neopixel example");
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setCursor(0, 25);
M5.Lcd.println("Display rainbow effect");
// Neopixel initialization
FastLED.addLeds<WS2811,Neopixel_PIN,GRB>\
(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(10);
xTaskCreatePinnedToCore(FastLEDshowTask, \
"FastLEDshowTask", 2048, NULL, 2, NULL, 1);
}
void loop(){
}
void FastLEDshowESP32(){
if (userTaskHandle == 0){
userTaskHandle = xTaskGetCurrentTaskHandle();
xTaskNotifyGive(FastLEDshowTaskHandle);
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
ulTaskNotifyTake(pdTRUE, xMaxBlockTime);
userTaskHandle = 0;
}
}
void FastLEDshowTask(void *pvParameters){
for(;;){
fill_rainbow(leds, NUM_LEDS, gHue, 7);// rainbow effect
FastLED.show();// must be executed for neopixel becoming effective
EVERY_N_MILLISECONDS( 20 ) { gHue++; }
}
}
2. UIFlow
完全なソースコードはこちら。
ピンマップ
| M5Core(GROVEインターフェースA) | GPIO22 | GPIO21 | 5V | GND |
| NEOPIXEL Unit | デジタルピン | 5V | GND |
関連動画
Neopixel デモ - 01
Neopixel デモ - 02