66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
#include <FastLED.h>
|
|
|
|
// FastLED配置
|
|
#define NUM_LEDS 2
|
|
#define DATA_PIN 21
|
|
CRGB leds[NUM_LEDS];
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
Serial.println("FastLED RGB灯测试开始...");
|
|
|
|
// 初始化FastLED
|
|
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
|
|
FastLED.setBrightness(50);
|
|
|
|
// 清除所有LED
|
|
FastLED.clear();
|
|
FastLED.show();
|
|
delay(1000);
|
|
|
|
Serial.println("测试第一个灯(索引0)...");
|
|
|
|
// 测试第一个灯 - 红色
|
|
leds[0] = CRGB::Red;
|
|
FastLED.show();
|
|
Serial.println("测试第一个灯(索引0) 红色");
|
|
delay(2000);
|
|
|
|
// 测试第一个灯 - 绿色
|
|
leds[0] = CRGB::Green;
|
|
FastLED.show();
|
|
Serial.println("测试第一个灯(索引0) 绿色");
|
|
delay(2000);
|
|
|
|
// 测试第一个灯 - 蓝色
|
|
leds[0] = CRGB::Blue;
|
|
FastLED.show();
|
|
Serial.println("测试第一个灯(索引0) 蓝色");
|
|
delay(2000);
|
|
|
|
Serial.println("测试第二个灯(索引1)...");
|
|
|
|
// 测试第二个灯 - 红色
|
|
leds[1] = CRGB::Red;
|
|
FastLED.show();
|
|
Serial.println("测试第二个灯(索引1) 红色");
|
|
delay(2000);
|
|
|
|
// 测试第二个灯 - 绿色
|
|
leds[1] = CRGB::Green;
|
|
FastLED.show();
|
|
Serial.println("测试第二个灯(索引1) 绿色");
|
|
delay(2000);
|
|
|
|
// 测试第二个灯 - 蓝色
|
|
leds[1] = CRGB::Blue;
|
|
FastLED.show();
|
|
Serial.println("测试第二个灯(索引1) 蓝色");
|
|
delay(2000);
|
|
|
|
Serial.println("测试完成");
|
|
}
|
|
|
|
void loop() {
|
|
// 空循环
|
|
} |