FastLED.setBrightness(brightness2);这段代码放在哪里?
时间: 2024-03-17 21:45:45 浏览: 149
FastLED-3.1.6.zip_FastLED.h_FastLED.h下载_arduino dmx_fast led_fas
5星 · 资源好评率100%
你可以在每次修改完亮度变量 `brightness2` 后,将新的亮度值赋给第二条灯带的亮度,也就是在以下代码之后添加:
```
brightness2 -= 10;
if (brightness2 > 255) {
brightness2 = 0;
}
FastLED.setBrightness(brightness2); // 将新的亮度值赋给第二条灯带的亮度
```
这样就能够修改第二条灯带的亮度了。完整的代码如下:
```
#include <FastLED.h>
#define LED_PIN 3
#define LED_PIN_2 6 // 定义第二条灯带的引脚
#define LED_COUNT 42
#define LED_COUNT_2 7 // 定义第二条灯带的 LED 数量
#define BRIGHTNESS 255
#define BRIGHTNESS_2 255
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[LED_COUNT];
CRGB leds_2[LED_COUNT_2]; // 定义第二条灯带的 LED 数组
int brightness2 = 0; // 定义初始亮度为 100
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, LED_COUNT);
FastLED.addLeds<LED_TYPE, LED_PIN_2, COLOR_ORDER>(leds_2, LED_COUNT_2); // 添加第二条灯带
FastLED.setBrightness(BRIGHTNESS);
FastLED.setBrightness(BRIGHTNESS_2);
}
void loop() {
/太阳灯带**/
// 将第二条灯带的所有 LED 设置为黄色
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 >= 1000) {
lastUpdateTime = currentTime;
brightness2 -= 10;
if (brightness2 > 255) {
brightness2 = 0;
}
FastLED.setBrightness(brightness2); // 将新的亮度值赋给第二条灯带的亮度
}
// 设置第二条灯带的亮度
FastLED.setBrightness(BRIGHTNESS_2);
// 更新 LED 灯带
FastLED.show();
}
```
阅读全文