#include <FastLED.h> #define LED_PIN_1 3 #define LED_PIN_2 6 #define LED_COUNT_1 53 #define LED_COUNT_2 7 #define BRIGHTNESS 255 #define LED_TYPE WS2812B #define COLOR_ORDER GRB CRGB leds_1[LED_COUNT_1]; CRGB leds_2[LED_COUNT_2]; void setup() { FastLED.addLeds<LED_TYPE, LED_PIN_1, COLOR_ORDER>(leds_1, LED_COUNT_1); FastLED.addLeds<LED_TYPE, LED_PIN_2, COLOR_ORDER>(leds_2, LED_COUNT_2); FastLED.setBrightness(BRIGHTNESS); } void loop() { int brightness_2 = 0; int fadeAmount = 5; for (int i = 0; i < 7680; i++) { int brightness_1 = (exp(sin(i / 50.0 * PI)) - 0.36787944) * 108.0; for (int j = 0; j < LED_COUNT_1; j++) { leds_1[j].setRGB(brightness_1, brightness_1, brightness_1); } FastLED.show(); delay(20); } }这段代码在灯带呼吸效果后面添加一个从中间向两端亮起的代码
时间: 2024-03-21 21:38:58 浏览: 119
以下是一个在灯带呼吸效果后面添加从中间向两端亮起的代码示例:
```
#include <FastLED.h>
#define LED_PIN_1 3
#define LED_PIN_2 6
#define LED_COUNT_1 53
#define LED_COUNT_2 7
#define BRIGHTNESS 255
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds_1[LED_COUNT_1];
CRGB leds_2[LED_COUNT_2];
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN_1, COLOR_ORDER>(leds_1, LED_COUNT_1);
FastLED.addLeds<LED_TYPE, LED_PIN_2, COLOR_ORDER>(leds_2, LED_COUNT_2);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
// 灯带呼吸效果
for (int i = 0; i < 7680; i++) {
int brightness_1 = (exp(sin(i / 50.0 * PI)) - 0.36787944) * 108.0;
for (int j = 0; j < LED_COUNT_1; j++) {
leds_1[j].setRGB(brightness_1, brightness_1, brightness_1);
}
FastLED.show();
delay(20);
}
// 从中间向两端亮起
int middle = LED_COUNT_1 / 2;
for (int i = 0; i <= middle; i++) {
int brightness = map(i, 0, middle, 0, BRIGHTNESS);
leds_1[middle - i] = CRGB(brightness, 0, 0);
leds_1[middle + i] = CRGB(brightness, 0, 0);
FastLED.show();
delay(20);
}
// 延迟一段时间,让灯带保持亮起状态
delay(500);
// 清空灯带
for (int i = 0; i < LED_COUNT_1; i++) {
leds_1[i] = CRGB(0, 0, 0);
}
FastLED.show();
}
```
这段代码先实现了一个灯带呼吸效果,然后在呼吸效果停止后,从中间向两端亮起灯珠,并让亮度逐渐增加,最后让灯珠保持亮起状态一段时间后熄灭。
阅读全文