jandelgado / jled

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

Repeat() and DelayAfter() on the same effect in a sequence #122

Closed mattbk closed 10 months ago

mattbk commented 10 months ago

When I run code like this, I would expect the first effect to repeat three times with a delay of three seconds after each time. But the first effect runs once and then it moves on to the next effect. Am I missing something?

It looks like Repeat() alone works as expected but DelayAfter() alone does not.

Modified from https://github.com/jandelgado/jled/blob/master/examples/sequence/sequence.ino.

#include <jled.h>

constexpr auto LED_PIN = 3;

JLed leds[] = {
    JLed(LED_PIN).Breathe(2000).Repeat(3).DelayAfter(1000),
    JLed(LED_PIN).Blink(750, 250).Repeat(3),
    JLed(LED_PIN).FadeOff(1000).Repeat(3),
    JLed(LED_PIN).Blink(500, 500).Repeat(3),
    JLed(LED_PIN).FadeOn(1000).Repeat(3),
    JLed(LED_PIN).Off(5000)
};

JLedSequence sequence(JLedSequence::eMode::SEQUENCE, leds);

void setup() { }

void loop() {
    sequence.Update();
    delay(1);
}

Thanks a bunch for the Morse example, I'm using it for exactly that purpose (to key a radio). The use case is that I want to repeat a Morse message n times, then wait a number of seconds. But without DelayAfter() on the message, the final dit and the first dah run together.

mattbk commented 10 months ago

I realized that for my use case, I can add an extra space (" ") at the end of the MorseEffect message, and the messages won't run together. I don't think this manual intervention is possible for regular LED sequences, though.

jandelgado commented 10 months ago

Thanks for the report - I can confirm that there is a problem in the JLed code, introduced recently (and not covered by tests...). Will investigate further ...

jandelgado commented 10 months ago

fixed with 4.13.1, please check if it's ok now

mattbk commented 10 months ago

Works a treat, thank you!