效果就是两边向中间过渡,值得当成一种效果.
/// @file RGBSetDemo.ino
/// @brief Demonstrates how to create an LED group with CRGBArray
/// @example RGBSetDemo.ino
#include <FastLED.h>
#define NUM_LEDS 100
CRGBArray<NUM_LEDS> leds;
void setup() { FastLED.addLeds<WS2812B, 2, RGB>(leds, NUM_LEDS); }
void loop(){
static uint8_t hue;
for(int i = 0; i < NUM_LEDS/2; i++) {
// fade everything out
leds.fadeToBlackBy(40);
// let's set an led value
leds[i] = CHSV(hue++,255,255);
// now, let's first 20 leds to the top 20 leds,
leds(NUM_LEDS/2,NUM_LEDS-1) = leds(NUM_LEDS/2 - 1 ,0);
FastLED.delay(33);
}
}
这个代码示例展示了如何使用FastLED库中的CRGBArray类来创建和操作一组LED。该代码的主要作用是在一个100个LED的阵列上创建一个动态的颜色变化效果,并使用CRGBArray类提供的功能来处理部分LED的操作。
代码解析
- 头文件与LED阵列定义
#include <FastLED.h>
#define NUM_LEDS 100
CRGBArray<NUM_LEDS> leds;