#include <FastLED.h> #define LED_PIN_1 3 #define LED_PIN_2 6 #define LED_COUNT_1 53 #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(0, brightness_1, 0); } FastLED.show(); delay(20); } }在呼吸灯之后增加一个效果,增加一个流水灯的效果
时间: 2024-03-21 17:43:42 浏览: 98
以下是增加流水灯效果的代码:
```
#include <FastLED.h>
#define LED_PIN_1 3
#define LED_PIN_2 6
#define LED_COUNT_1 53
#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(0, brightness_1, 0);
}
// 流水灯效果
for (int j = 0; j < LED_COUNT_2; j++) {
leds_2[j] = CRGB::Black; // 先将所有LED设置为黑色
leds_2[((i/20)+j)%LED_COUNT_2] = CRGB::Red; // 设置流水灯的红色
}
FastLED.show();
delay(20);
}
}
```
在此代码中,增加了一个for循环来控制流水灯效果。在每个循环中,使用for循环来逐个设置LED的颜色。在每个流水灯的位置设置红色,其他LED设置为黑色。使用模运算和延迟来控制流水灯的速度和效果。
阅读全文