1

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.

Its documentations states:

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.

4
  • Why don't you just use lower UPDATES_PER_SECOND?
    – KIIV
    Commented Aug 9, 2016 at 13:41
  • I've tried, but even at 30 its faster than setting the index to 0.1, and also prevents faster animations.
    – Nah
    Commented Aug 9, 2016 at 14:35
  • "But i found the motion speed too fast. its stated in this:" "and also prevents faster animations. " I'm confused what do you want? Commented Aug 10, 2016 at 12:39
  • Change FastLED.delay(1000 / UPDATES_PER_SECOND); to FastLED.delay(1000); and tell me what happens or change #define UPDATES_PER_SECOND 100 to #define UPDATES_PER_SECOND 1
    – Martynas
    Commented May 7, 2017 at 19:48

2 Answers 2

1

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.