我有个问题。我正在使用 Arduino 控制我的 WS2812B,但我的呼吸效果有问题。我在代码中创建了一个类,如下所示:
String breathDirection = "Down";
void breath_effect()
{
fill_solid(leds, TOTAL_LEDS, primary);
float currentBrightness = FastLED.getBrightness();
if (currentBrightness <= 1)
{
breathDirection = "Up";
}
else if (currentBrightness >= brightness)
{
breathDirection = "Down";
}
float brightnessCorrection = static_cast<float>(brightness) / 200;
if (breathDirection == "Down")
{
currentBrightness = currentBrightness - brightnessCorrection;
FastLED.setBrightness(currentBrightness);
}
else if (breathDirection == "Up")
{
Serial.println("Binnen");
Serial.println(currentBrightness);
currentBrightness = currentBrightness + brightnessCorrection;
Serial.println(currentBrightness);
FastLED.setBrightness(currentBrightness);
}
}
现在呼吸效果仅在brightness
变量设置为 200 时有效。如果我将其设置为低于 200 的其他值,它会下降,但永远不会上升。currentBrightness 是每一轮相同的值。这里出了什么问题?