I'm working on a code based on PaletteCrossfade.ino example. But I found the motion speed too fast. It's stated in this:
static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors(startIndex);
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}
void FillLEDsFromPaletteColors( uint8_t colorIndex) {
uint8_t brightness = 255;
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex + sin8(i*16), brightness);
colorIndex += 3;
Since the startIndex defined in uint8_t
, it cant be lower than 1. So I used float and set it to 0.2 in my code. Which seems to work, and animation slowed down. However I'm not sure how is that float value added into the ColorFromPalette
function.
CRGB ColorFromPalette (const CRGBPalette16 &pal, uint8_t index, uint8_t brightness=255, TBlendType blendType=LINEARBLEND)
To my understanding it accepts only integer, and also int based sin8 being added to float value. So, what exactly happens there? Is this method viable, or is there any better way to slow down the animation?
I'm thinking about adding a millis() based delay and only increasing the colorindex every 2-3 seconds or so.
2 Answers 2
The code you have seems to fill the lights with a colour and change every nth of a second. You could control that to change every 1ms to 2^16ms (which is 65 seconds) just by changing the FastLED.delay() value.
sin8() might return a float or I suspect an int, but colourIndex is an uint8_t so that is a whole number. All it is doing is picking a colour, based on some scheme. If the value passed to the function is a float i.e. 1.611 then it will be converted to an int by taking just the whole number part, in this case 1. It does not round up.
Its not clear what you are trying to do.
If you are trying to slow the rate that the LEDs change colour, you need to change the delay statement.
If you want to smooth the transition between colours you need to change in the area of the sin8 statement, but what you change it to will depend on what your palette is loaded with.
Hope that helps, if not please can you try and describe what it is you are tying to achieve.
In order to change the update rate you have to change it.
You have two choices in ColourPalette example:
1st:
LINE 10
#define UPDATES_PER_SECOND 100 // higher number means more frames a second
2nd:
LINE 58
FastLED.delay(1000 / UPDATES_PER_SECOND); // change it to:
FastLED.delay(2000); //2000ms means 0.5 frame per second or 1 frame every two seconds
UPDATES_PER_SECOND
?FastLED.delay(1000 / UPDATES_PER_SECOND);
toFastLED.delay(1000);
and tell me what happens or change#define UPDATES_PER_SECOND 100
to#define UPDATES_PER_SECOND 1