Hi,
I have just a quick question. How long is the pulse (in ms) generated by EVERY_N_SECONDS()? I have searched the sourcecode, but haven’t found anything meaningful.
Thank you.
Hi,
I have just a quick question. How long is the pulse (in ms) generated by EVERY_N_SECONDS()? I have searched the sourcecode, but haven’t found anything meaningful.
Thank you.
That macro does not generate any pulses. It just executes the code you provide at the given time interval. It’s shorthand for something like this:
static uint32_t lastTime = 0;
if (millis() - lastTime > N*1000) {
…your code…
lastTime = millis();
}
@Sam_Guyer I think lastTime = millis(); has to be right after the if, otherwise the actual interval time is affected by the time it takes for …your code… to execute.
@Franck_Marcotte Good point. Depends on how precise you need the timing.
Maybe I haven’t specified my question clearly. I mean, how long a LED shines, when using the following code as an example:
EVERY_N_SECONDS(5) { Led_no_19[19] = CRGB::Red; }
FastLED.show();
So it will blink every 5 seconds, but how long does the “blink” last? I need to know that, because I plan to use it for a precise light irradiation.
P.S. I’m using WS2812B
Thank you
It will not blink. You just tell it to change the color to red every 5 seconds, but it won’t get switched off?
@Thomas_Balu_Walter No, it blinks and works perfectly well, but not sure how long the blink is. The whole code is as follows:
#include “FastLED.h”
#define NUM_LEDS_PER_STRIP 96
CRGB strip_at_PIN7[NUM_LEDS_PER_STRIP];
void setup() {
FastLED.addLeds<NEOPIXEL, 7>(strip_at_PIN7, NUM_LEDS_PER_STRIP);
}
void loop() {
FastLED.clear ();
FastLED.setBrightness(255);
EVERY_N_SECONDS(5) { strip_at_PIN7[19] = CRGB::Red; }
FastLED.show();
}
Ah, ok. So you FastLED.clear() it at the beginning of the loop. It is then on for as long as it takes to loop from one FastLED.show() to the next FastLED.show().
So the more stuff you do inside of the loop(), the longer it will be on.
@Thomas_Balu_Walter OK, Thank you for clarification.