I have been working on a little project, and particularly for this post, a certain function. It’s based off a piece of a FastLED example that I can’t find at the moment to reference.
it looks like this
for( byte i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex + sin8(i * sinVal), brightVal, LINEARBLEND);
colorIndex += 3;
}
over time, using a “millis() - trackTime > 1000” if statement, sinVal gets pushed up one digit. After a few upticks it decreases to the original value at the same rate.
This all looks fine but when the value changes a noticeable shift occurs.
I’m wondering how I could smooth this transition. The value only changes one digit which I though would not be noticeable. I would like to somehow blend it into the for loop rather than instantly changing the value.
I had a look but didn’t figure it out. If you pick a LED (I picked 6) and print the RGB values to the serial monitor you can see when it jumps. Maybe that will give you a clue of where to keep investigating. Put this inside your for loop at line 102:
if (i == 6) {
Serial.print(" RGB:\t"); Serial.print(leds[i].r);
Serial.print("\t"); Serial.print(leds[i].g);
Serial.print("\t"); Serial.println(leds[i].b);
}
Regarding your question about line 132, 133:
the variable is declared and set to start at 0, and then after that it adds + 1 on each loop. Since the variable was declared as uint8_t when it goes above 255 it will roll back over to 0 and start counting up again.
Ok, that’s a great idea. Thanks for taking a look at it for me. I will investigate with the serial monitor.
Thank you for answering my other question. I used the serial monitor to see what kind of output was given. You are right, it goes from 0 to 255 then repeats. I am confused as to why it does not stay at 1 though. In the loop it is declared as 0 then is told to add one. Why does the loop not reset back at 0 each time it starts over?