LED.Timer (led v0.1.1)

View Source

Timer helper functions for managing LED blinking and repeating patterns.

Provides mechanisms to send timed messages for blinking intervals, including support for infinite repeats and countdowns.

Summary

Functions

Cancels a list of timer references to stop scheduled timer messages.

Schedules the next timer message for LED blinking or repeating patterns.

Functions

cancel(timer_refs)

(since 0.1.0)
@spec cancel([reference()]) :: list()

Cancels a list of timer references to stop scheduled timer messages.

  • timer_refs is a list of references returned by Process.send_after/3.
  • If a nil timer_ref is encountered, logs a debug message and skips cancellation.

send_timer(message)

(since 0.1.0)
@spec send_timer({0 | 1, integer(), integer()}) :: nil | reference()

Schedules the next timer message for LED blinking or repeating patterns.

  • Accepts a tuple {state, interval, times} where:

    • state is 0 (off) or 1 (on).
    • interval is the delay in milliseconds before sending the next message.
    • times is the number of remaining toggles; -1 means infinite repeats.
  • If times is -1, schedules the timer infinitely.

  • If times is 0, does nothing (no timer scheduled).

  • If state is 0, decrements times and schedules the next timer.

  • If state is 1, schedules the next timer without decrementing times.

Returns the timer reference or nil if no timer is scheduled.