One of the FastLED examples that I've seen was using code that looks like this:

EVERY_N_MILLISECONDS( 300 ) { transition_step(); }

I've copied it and successfully used it in the same context - but I have no idea what it is or how it works.

A Google search finds no reference anywhere at all.

I'm still a beginner with C but this looks like a Define to me - all being in uppercase - is it defined somewhere in the FastLED library?


Yes, it is defined in the FastLED library. It is a preprocessor macro which is replaced by a block of code when compiled:

It is a very convoluted bit of preprocessing code that is difficult (even for me) to follow through with lots of concatenations and multiple layers of definition, so my advice is to just not worry about it and just use it.

If you want to try and decypher it all it's in the file lib8tion.h in the FastLED library.

  • Excellent answer, thank you Majenko. If it's that complicated then I almost certainly won't be able to decypher it without a lot of headache, I mainly wanted to be sure I wasn't misunderstanding something fundamental about the language. I'm guessing that I can't have the thing appearing twice then if it defines Functions...? – Lefty Jan 20 '16 at 12:17

As @Majenko has said it is defined in the FastLED library http://fastled.io/. There is also EVERY_N_SECONDS.

It is not necessary to call any other FastLed function in the run loop (such as FastLED.delay()) in order to use these functions.

include <FastLED.h>

void loop() {
   EVERY_N_MILLISECONDS( <mseconds> ) { 
     <your timed code here>; 

   EVERY_N_SECONDS( <seconds> ) { 
     <your timed code here>; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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