View Source Delux.Effects (delux v0.4.0)
Functions for creating a variety of LED patterns
Link to this section Summary
Types
Options for all effects (none yet)
Functions
Blink an indicator
Create a transient two color sequence
Cycle between colors
Blink out a number
All LEDs off
Set an indicator to the specified color
Create a program to verify timing
Create a program from an arbitrary function
Link to this section Types
@type common_options() :: []
Options for all effects (none yet)
Link to this section Functions
@spec blink(Delux.RGB.color(), number(), common_options()) :: Delux.Program.t()
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.
@spec blip(Delux.RGB.color(), Delux.RGB.color(), common_options()) :: Delux.Program.t()
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.
@spec cycle([Delux.RGB.color()], number(), common_options()) :: Delux.Program.t()
Cycle between colors
Colors are shown with equal duration determined from the specified frequency.
@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)
@spec off() :: Delux.Program.t()
All LEDs off
@spec on(Delux.RGB.color(), common_options()) :: Delux.Program.t()
Set an indicator to the specified color
@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:
- 100 ms on
- 10 ms off
- 1 ms on
- 10 ms off
- 2 ms on
- 10 ms off
- 3 ms on
- 10 ms off
- 5 ms on
- 10 ms off
- 8 ms on
- 10 ms off
- 13 ms on
- 10 ms off
- 100 ms on
- off
Look at the following in the capture:
- 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.
- 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.
@spec waveform( (Delux.Pattern.milliseconds() -> Delux.RGB.color()), Delux.Pattern.milliseconds(), keyword() ) :: Delux.Program.t()
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.