void loop() { int brightness_2 = 0; int fadeAmount = 5; val = digitalRead(pin); //读取模拟接口的值 Serial.println(val);//输出模拟接口的值 if (val == 0) //如果Pin10检测的值为高电平,点亮LED { for (int i = 0; i < LED_COUNT_1; i++ ) { leds_1[i] = CRGB::White; FastLED.show(); delay(25); } } else //如果为低电平熄灭LED { 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 21:44:16 浏览: 59
根据前面提到的问题,可以将代码修改为如下形式:
```
void loop() {
int fadeAmount = 5;
val = digitalRead(pin); // 读取模拟接口的值
Serial.println(val);// 输出模拟接口的值
if (val == HIGH) { // 如果Pin10检测的值为高电平,点亮LED
for (int i = 0; i < LED_COUNT_1; i++) {
leds_1[i] = CRGB::White;
FastLED.show();
delay(25);
leds_1[i] = CRGB::Black;
}
} else { // 如果为低电平,熄灭LED
for (int i = 0; i < 3840; 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, 0, 0); // 红色通道
leds_1[j].setRGB(0, brightness_1, 0); // 绿色通道
leds_1[j].setRGB(0, 0, brightness_1); // 蓝色通道
}
FastLED.show();
delay(10);
}
}
}
```
注意,上述代码只是根据前面提到的问题进行了修改,如果还有其他问题需要进行修改的话,请提出来。
阅读全文