I;m writing an arduiuno code that is uploaded to an ESP32 to have a fire animation along 4 LED stirps at the same time. As of right now only the two strips for the fire_led_1 and fire_led_2 are working. The altar columns and windows belong to the breathingAnimation and breathingAnimation2 functions. I believe the problem is with getting to those functions and not the functions themselves if that makes sense.
Here is my loop function:
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);
}
Here is my step function:
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;
}
}
And here is one of the breathingAnimation functions (they are basically the same except the other has altar_columns instead of 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);
}
I’ve tried getting rid of the third case statement and having the breathingAnimation inside the first and second case statements and reordering my functions to see if maybe something was wrong with when it was called but there has been no change, only the first 2 LED strips are working
You have a logic error. You have no code path that can produce a signal_count
of 2
.
In other words, there is no signal_count++;
inside an if
condition when signal_count == 1
.
You’ll have to correct the logic to increment signal_count
from 1
to 2
at an appropriate place according to your requirements.
I can’t be certain what you intended, especially since this block is a do-nothing:
if (button.fell() && signal_count == 3){
signal_count = 3; // it's already 3 though. ?
}
And furthermore, it looks like there’s no distinction between step
and signal_count
(they change together).
But it’s possible that this could be the logic you need:
void plcControl() {
button.update();
if (button.rose()) {
if (signal_count == 0) {
signal_count++;
step = 1;
} else if (signal_count == 2) {
signal_count++;
step = 3;
}
} else if (button.fell()) {
if (signal_count == 1) {
signal_count++;
step = 2;
}
}
}
1