for (int i = 0; i < LED_COUNT_2; i++) { leds_2[i] = CRGB(255, 255, 0); } // 每隔2秒增加亮度 static unsigned long lastUpdateTime = 0; unsigned long currentTime = millis(); if (currentTime - lastUpdateTime >= 2000) { lastUpdateTime = currentTime; brightness2 += 10; if (brightness2 > 255) { brightness2 = 0; } } // 设置第二条灯带的亮度 FastLED.setBrightness(BRIGHTNESS_2); // 更新 LED 灯带 FastLED.show();初始亮度调整为0
时间: 2024-03-19 18:43:00 浏览: 134
这段代码是用来控制LED灯带的亮度和颜色的。首先,它会将LED灯带的颜色设置为黄色(RGB值为255,255,0),然后每隔2秒钟就会将亮度增加10,直到亮度达到255后再次变为0。最后,它会将LED灯带的亮度设置为BRIGHTNESS_2,并更新LED灯带的显示。初始亮度调整为0表示LED灯带最开始是暗的。
相关问题
// 闪烁两次黄光 for (int i = 0; i < 3; i++) { // 点亮所有灯珠,颜色为黄色 for (int j = 0; j < LED_COUNT_1; j++) { leds_1[j] = CRGB::Yellow; } FastLED.show(); delay(200); // 熄灭所有灯珠 for (int j = 0; j < LED_COUNT_1; j++) { leds_1[j] = CRGB::Black; } FastLED.show(); delay(200); }灯光颜色改为橘色
要将上述代码中的灯光颜色改为橘色,只需要在第6行将CRGB::Yellow改为CRGB::Orange即可。修改后的代码如下:
```
// 闪烁两次橘光
for (int i = 0; i < 3; i++) {
// 点亮所有灯珠,颜色为橘色
for (int j = 0; j < LED_COUNT_1; j++) {
leds_1[j] = CRGB::Orange;
}
FastLED.show();
delay(200);
// 熄灭所有灯珠
for (int j = 0; j < LED_COUNT_1; j++) {
leds_1[j] = CRGB::Black;
}
FastLED.show();
delay(200);
}
```
#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); } }这段代码怎么让第一条灯带呼吸的同时,第二条灯带一点点由暗变亮
你可以在第一个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()函数的参数。
阅读全文