Hello! New to the community,

(Jeremy McCabe) #1

New to the community, I have been using the Neopixel library and have been switching over to FastLED because of the obvious advantages. I’m getting stuck on the EVERY_N_MILLIS function and how to use it properly. I want to use it in a for loop to control the speed of an animation. For Example:

void wipe( CRGB color, uint8_t wait) {

for (int i=0 ; i < NUM_LEDS; i++) {
leds[i] = color;
EVERY_N_MILLIS(wait); //Tried Here
EVERY_N_MILLIS(wait); //Tried Here
But it does not seem to make a difference

(Steve Anken) #2

Something like this?


(Jeremy McCabe) #3

@Steve_Anken that does work, but I don’t want to lock it up with a delay. It doesn’t allow me to do monitor button states during the animation.

(Ken White) #4

@Jeremy_McCabe - Here is a sketch of mine that that illustrates how to use EVERY_N_MILLIS to replace a delay in a function:

(Jeremy McCabe) #5

perfect! I edited it a bit so it stops at the end of a button press and clears when released.

(Andrew Tuline) #6

That’s an interesting take that Ken has on the EVERY_N_MILLIS call. I do it by:

void loop () {
FastLED.show(); // I always keep this in the loop.

void coolfunction() {
// Do awesome stuff.

The advantage Ken’s has is that each display routine you call can have separate wait times, whereas mine is a one size fits all unless I change the wait value on the fly. Hmm, choices, choices.

(Jeremy McCabe) #7

Ken’s way was perfect for me, I had too many delays in my Neopixel sketch all over the place. This way allowed me to change the speed when calling the function. Worked extremely well.