jandelgado / jled

Non-blocking LED controlling library for Arduino and friends.
MIT License
331 stars 55 forks source link

Change time of efect in loop function #34

Closed petione closed 5 years ago

petione commented 5 years ago

How I can change time of effect in loop function or add variable as time?

include

include

// blink internal LED every second; 1 second on, 0.5 second off. auto led = JLed(LED_BUILTIN).Blink(100, 500).Forever(); void setup() {} void loop() { led = JLed(LED_BUILTIN).Blink(1000, 500).Forever(); //this not work led.Update(); }

jandelgado commented 5 years ago

This does not work because you are re-assigning the led object again and again in the loop() function. You need some kind of a trigger and re-assign only once, e.g. (not tested):

...
auto changed = false;
...
void loop() {
     static auto time_start = millis();
     if (millis() - time_start > 5000 && !changed) {
         changed = true;
         led = JLed(LED_BUILTIN).Blink(1000, 500).Forever(); 
    }   
    led.Update();
}
petione commented 5 years ago

I'm understand. Thanks for reply.