conflicting declaration 'uint8_t brightness'
时间: 2023-07-24 12:35:23 浏览: 100
这个错误的原因是 `brightness` 变量被重复定义了。可以将 `brightness` 定义在 `loop()` 函数外面,这样它就不会被重复定义了。修改后的代码如下:
```cpp
#include <FastLED.h>
#define LED_PIN_1 3
#define LED_PIN_2 4
#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];
uint8_t brightness = 0;
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() {
brightness++;
for (int i = 0; i < LED_COUNT_1; i++) {
leds_1[i] = CHSV(0, 255, brightness);
}
for (int i = 0; i < LED_COUNT_2; i++) {
leds_2[i] = CHSV(60, 255, brightness);
}
FastLED.show();
delay(50);
}
```
这样就可以避免上面提到的错误了。
阅读全文