#include <FastLED.h> #define LED_PIN_1 3 #define LED_PIN_2 6 #define LED_COUNT_1 42 #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); } 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); } }这段代码怎么让第一条灯带呼吸的同时,第二条灯带一点点由暗变亮
时间: 2024-03-17 16:46:26 浏览: 150
LED_board:将Arduino连接到LED板!
你可以在第一个while循环中,每次让第二条灯带的亮度增加一点,如下所示:
```
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);
// 让第二条灯带的亮度增加1
for (int i = 0; i < LED_COUNT_2; i++) {
leds_2[i].fadeLightBy(1);
}
}
```
这样,第二条灯带的亮度就会慢慢增加,同时第一条灯带会呼吸。你可以根据需要调整第二条灯带亮度增加的速度,即调整第二个for循环中的fadeLightBy()函数的参数。
阅读全文