第一条灯带保持呼吸灯状态,不要一点点变亮
时间: 2024-01-21 14:18:02 浏览: 113
好的,可以将代码修改为:
```
#include <FastLED.h>
#define LED_PIN_1 3
#define LED_PIN_2 5
#define LED_COUNT_1 42
#define LED_COUNT_2 42
#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 < 256; 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(25);
}
while (brightness_2 <= 255) {
for (int i = 0; i < LED_COUNT_2; i++) {
leds_2[i].setRGB(255, 255, 0);
leds_2[i].fadeLightBy(brightness_2);
}
FastLED.show();
brightness_2 += fadeAmount;
delay(25);
}
while (brightness_2 >= 0) {
for (int i = 0; i < LED_COUNT_2; i++) {
leds_2[i].setRGB(255, 255, 0);
leds_2[i].fadeLightBy(brightness_2);
}
FastLED.show();
brightness_2 -= fadeAmount;
delay(25);
}
}
```
这个代码会让第一条灯带保持呼吸灯的状态,然后第二条灯带从灭的状态开始,一点一点变成黄色并且变亮,最后第二条灯带再一点一点变暗。你可以调整 `delay()` 函数的参数来改变呼吸灯的速度。
阅读全文