我正在编写一个上传到 ESP32 的 arduiuno 代码,以便同时沿着 4 个 LED 搅拌棒产生火焰动画。截至目前,只有 fire_led_1 和 fire_led_2 的两个灯条正在工作。祭坛柱和窗户属于呼吸动画和呼吸动画2功能。我认为问题在于获取这些函数而不是函数本身(如果这有意义的话)。
这是我的循环函数:
void loop() {
switch (step) {
case 0: // First fire animation
igniteTrail(fire_strip_1);
igniteTrail(fire_strip_2);
fireAnimation(fire_strip_1);
fireAnimation(fire_strip_2);
breathingAnimation2(altar_columns);
breathingAnimation2(altar_windows);
plcControl();
input_LED();
fire_strip_1.setBrightness(255);
fire_strip_2.setBrightness(255);
break;
case 1: // Fire goes out
stripsOff();
plcControl();
input_LED();
break;
case 2: // Fire gets stronger
secondFire();
fire_strip_1.setBrightness(currentBrightness);
fire_strip_2.setBrightness(currentBrightness);
fireAnimation(fire_strip_1);
fireAnimation(fire_strip_2);
breathingAnimation(altar_columns);
breathingAnimation2(altar_windows);
plcControl();
input_LED();
Serial.println(currentBrightness);
break;
case 3:
fire_strip_1.setBrightness(currentBrightness);
fire_strip_2.setBrightness(currentBrightness);
fireAnimation(fire_strip_1);
fireAnimation(fire_strip_2);
breathingAnimation2(altar_columns);
breathingAnimation(altar_windows);
plcControl();
input_LED();
break;
}
brightnessElapsedTime = millis(); //Get the current time
Serial.println(step);
}
这是我的步骤函数:
void plcControl() { // controls what step of the animation the lighting controller is on based on how many PLC inputs have been recieved
button.update();
if (button.rose() && signal_count == 0) {
signal_count++;
step = 1;
}
if (button.fell() && signal_count == 1) {
step = 2;
}
if (button.rose() && signal_count == 2) {
signal_count++;
step = 2;
}
if (button.fell() && signal_count == 3){
signal_count = 3;
}
if (button.rose() && signal_count == 3){
signal_count++;
step = 3;
}
}
这是呼吸动画函数之一(它们基本相同,除了另一个有 altar_columns 而不是 altar_windows):
void breathingAnimation(Adafruit_NeoPixel &altar_windows) {
static int brightness = 30;
static int fadeAmount = 5; // adjust this value to change the speed of the animation
brightness = brightness + fadeAmount;
if (brightness <= 30 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
altar_windows.setBrightness(brightness);
for (int i = 0; i < altar_windows.numPixels(); i++) {
altar_windows.setPixelColor(i, altar_windows.Color(255, 40, 0)); // Set all pixels to orange color
}
altar_windows.show();
delay(25);
}
我尝试摆脱第三个 case 语句,并在第一个和第二个 case 语句中添加呼吸动画,并重新排序我的函数,看看调用它时是否有问题,但没有任何变化,只有前 2 个LED 灯条正在工作
你有一个逻辑错误。 您没有可以生成
signal_count
的代码路径。换句话说,当 2
时,
signal_count++;
条件内不存在 if
。您必须根据您的要求在适当的位置更正逻辑,将 signal_count == 1
从
signal_count
增加到 1
。