Can anyone tell me why this code runs so slow?

Can anyone tell me why this code runs so slow? It takes about 1.4 seconds to get a dot to run across 210 neopixels with no delay in the loop.

Arduino: 1.8.2
FastLED version 3.001.003
UNO board

--------------

#include “FastLED.h”
#include <avr/wdt.h>

FASTLED_USING_NAMESPACE
#define NUM_LEDS 210 //0.3W per LED, so,
#define DATA_PIN 6
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB

// Globals
CRGB leds[NUM_LEDS];

void setup() {
interrupts();
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
}

void loop()
{
int position = 0;
bool keep_going=true;

  while (keep_going)
  { 
    if (position == 209)
      keep_going = false;
    
    fadeToBlackBy(leds, NUM_LEDS, 100);  // Dim what's been done before
    leds[position] = CHSV(0,255,255);  // Activate latest position
    
    FastLED.show();

    position++;
  }

}

Don’t have a controller to actually try running it right now, but I don’t see anything that would cause a slow down. Strange.

I think it takes ~30uS per WS2812 to write data out. 30uS * 210 LEDs = 6.3mS per frame * 210 frames = 1.323 seconds.

Maybe it’s just that. :stuck_out_tongue:

I was going to ask what if you comment out the include for the watch dog timer?

@Jason_Coon Well that certainly explains that. I’m going to hunt down the actual timing fastled does and see if I can code something that calculates how to jump more or less depending on how fast I want it to go. Thank you.

Coding your animations around millis() and micros() is useful to control the timing. For example, you could check how much time has passed since the last loop and increment your dot position accordingly.

Yeah, or use any of the wave generator functions in FastLED, or beat8 which sweeps from 0 to 255 at an interval you specify (0 to 255 beats per minute). At high rates it will skip numbers, but you can keep track of the previous position and fill to the new position, like this: https://gist.github.com/kriegsman/261beecba85519f4f934

@Jason_Coon That is super helpful. This library is incredible. Going to play with it when I get home!

Can someone explain the timebase and phase_offset arguments in the beat functions? I’m trying to find a way to reset the beatsin16 function so that after I run the cylon once, I can run it again and still start at zero the second time (and every other time after). I’m guessing the other arguments might have something to do with it but experimentation hasn’t gotten me anywhere. A search in the documentation for timebase came up with zero. If there’s a way to use the documentation to find it next time, I’d love to learn how.