Delux.Effects (delux v0.4.1)

Copy Markdown View Source

Functions for creating a variety of LED patterns

Summary

Types

Options for all effects (none yet)

Functions

Create a transient two color sequence

All LEDs off

Set an indicator to the specified color

Create a program to verify timing

Create a program from an arbitrary function

Types

common_options()

@type common_options() :: []

Options for all effects (none yet)

Functions

blink(c, frequency, options \\ [])

Blink an indicator

This returns a pattern that blinks the specified color at a 50% duty cycle. The pattern starts on and then goes off.

blip(c1, c2, options \\ [])

Create a transient two color sequence

The first color is shown for 20 ms. 10 ms in, the second color is shown for 20 ms. The Effects is a quick flash of light that can be used to show feedback to a button. Total duration of the Effects is 40 ms.

cycle(colors, frequency, options \\ [])

Cycle between colors

Colors are shown with equal duration determined from the specified frequency.

number_blink(c, count, options \\ [])

@spec number_blink(Delux.RGB.color(), 1..20, number_blink_options()) ::
  Delux.Program.t()

Blink out a number

This returns a pattern that blinks out a number. It's good for communicating small numbers to viewers. It repeats.

Options:

  • :inter_number_delay - the amount of milliseconds to wait in between blinking out the count (defaults to 2000 ms)
  • :blink_on_duration - how long to keep the LED on when blinking (defaults to 250 ms)
  • :blink_off_duration - how long to keep the LED off when blinking (defaults to 250 ms)

off()

@spec off() :: Delux.Program.t()

All LEDs off

on(c, options \\ [])

Set an indicator to the specified color

timing_test(c, options \\ [])

@spec timing_test(Delux.RGB.color(), common_options()) :: Delux.Program.t()

Create a program to verify timing

If you're unsure about the playback timing on your device, hook up a logic analyzer to an LED and capture the waveform. Here's what you should see:

  1. 100 ms on
  2. 10 ms off
  3. 1 ms on
  4. 10 ms off
  5. 2 ms on
  6. 10 ms off
  7. 3 ms on
  8. 10 ms off
  9. 5 ms on
  10. 10 ms off
  11. 8 ms on
  12. 10 ms off
  13. 13 ms on
  14. 10 ms off
  15. 100 ms on
  16. off

Look at the following in the capture:

  1. Do the 1, 2, 3, 5 ms captures match what you'd expect based on your kernel's HZ setting. For example, if HZ=100, they should all be 10 ms long. If not, check the :hz setting for Delux.
  2. Does the length of the final 100 ms on time match the first. If not, Delux might be calculating the duration wrong and cutting off the program prematurely. This is likely due to an incorrect :hz setting.

If something still isn't right, please submit an issue with the captured waveform and any other hints you may have to reproduce.

waveform(fun, period, options \\ [])

Create a program from an arbitrary function

Pass in a function that takes times in milliseconds and returns colors. The returned pattern piecewise linearly interpolates the waveform.

Here's an example of a 0.5 Hz blue sine wave:

Effects.waveform(fn t -> {0, 0, 0.5 + 0.5 *:math.cos(:math.pi() * t /  1000)} end, 2000)

When trying this, keep in mind that if the LEDs in the indicator don't support varying levels of brightness, it won't look like a sine wave.

Options

  • :time_step - the number of milliseconds between each sample. Defaults to 100 ms.