I am changing a variable with a predetermined rate. When my variable gets too large, I cap it back to the largest value I want to make it, and change the sign on the rate to make the change go the other direction.
x += rate;
if (x > 255){
rate = -rate;
x = 255;
}
if (x < 0) {
rate = -rate;
x = 0;
}
However (when I execute this code and use the variable to control the brightness of some LEDs), once x goes to or above my highest threshold, it resets to the lower value and goes up again.
None of the other code manipulates or uses x, unless when I am setting CRGB values with x to an LED array. This code runs in void(loop).