Fledex.Leds (fledex v0.5.0)
View SourceThis module allows to define a sequence of Leds. You first create the new sequence of leds
by calling one of the leds
functions.
Note: usually the leds
function would rather be called new
but when importing the Leds
module, it becomes more natural to say
leds(10) |> light(:red)`
To keep the classical semantics some delegates are defined, so you can use new
as well.
Summary
Functions
Helper function to convert a list of colors to the correct map structure
This function checks how many leds are defined in the led sequence.
Retrieve the color of an led at a specific position
Defines the leds through a gradient function.
Create a new led sequence of length 0.
Creates a new led sequence with a set number of leds
Create a new led sequence with a set number of leds and some options.
Create a new led sequence with a set number of leds, some set leds and options.
Creates a led sequence with a set number of leds, some set leds, some options and some meta information.
Defines the color(s) of the next led
Defines the color of an led with some options specified.
See Fledex.Leds.leds/0
.
Defines a rainbow over the leds. The options that can be specified are
repeat the existing sequence amount
times
Convenience function to send the led sequence to an Fledex.LedStrip
.
This function sets the count of leds of the led sequence.
Define the server_name and the namespace
Convert the sequence of leds to a binary sequence of Fledex.Color.Types.colorint
colors.
Convert the sequence of leds into an list of Fledex.Color.Types.colorint
colors.
Convert the sequence of leds to a markdown representation.
Types
@type t() :: %Fledex.Leds{ count: integer(), leds: %{required(pos_integer()) => Fledex.Color.Types.colorint()}, meta: %{required(atom()) => any()}, opts: %{required(atom()) => any()} }
Functions
@spec convert_to_leds_structure([Fledex.Color.Types.color()], integer()) :: map()
Helper function to convert a list of colors to the correct map structure
@spec count(t()) :: pos_integer()
This function checks how many leds are defined in the led sequence.
Note: The color of an led outside that range can be defined, but it won't be
send to the Fledex.LedStrip
when the send/2
function is called. See also
set_count/2
for information.
@spec get_light(t(), pos_integer()) :: Fledex.Color.Types.colorint()
Retrieve the color of an led at a specific position
@spec gradient(t(), Fledex.Color.Types.color(), Fledex.Color.Types.color(), keyword()) :: t()
Defines the leds through a gradient function.
The gradient function will create a smoot transition from a start_color
to an
end_color
. The options that can be specified are the following:
"num_leds
: Over how many leds the transition should happen. (default: all):offset
: The offset where to start the gardient at (default: 0)
@spec leds() :: t()
Create a new led sequence of length 0.
This is rarely useful. Use the leds/1
function instead (or change the count by using set_count/2
)
Creates a new led sequence with a set number of leds
Create a new led sequence with a set number of leds and some options.
Currently two options are available:
:server_name
and:namespace
.
Those are important when you want to send your led sequence to an
Fledex.LedStrip
.
You should prefer to use the set_led_strip_info/3
function instead.
@spec leds( integer(), [Fledex.Color.Types.color()] | %{required(integer()) => Fledex.Color.Types.color()}, map() ) :: t()
Create a new led sequence with a set number of leds, some set leds and options.
This function is similar to leds/2
, but you an specify some leds (between the count
and the opts
) through a map or a list.
If a map is used the key of the map (an integer) is the index (one-indexed) of the led and the value is the color. If a list is used each entry in the list defines a color. Internally it will be converted to a map.
Leds that are outside the count
can be specified, but will be ignored when sent to
an Fledex.LedStrip
through the send/2
function.
@spec leds( integer(), [Fledex.Color.Types.color()] | %{required(integer()) => Fledex.Color.Types.color()}, map(), map() ) :: t()
Creates a led sequence with a set number of leds, some set leds, some options and some meta information.
This function is similar to the leds/3
function, but some additional meta information
can be specified. Currently the only meta information is to keep track of an index
that specfies which led will be set when using the light/2
function, i.e. without
an offset. This way it's possible to have a sequence of updates like the following
to specify the colors:
leds(10) |> light(:red) |> light(:blue)
@spec light(t(), Fledex.Color.Types.color() | t()) :: t()
Defines the color(s) of the next led
If there are no more leds, this function will virtually continue and define leds
outside the scope, see also the note on set_count/2
.
Note: it is possible to use a sub sequence of leds and they all will be added to the sequence.
@spec light(t(), Fledex.Color.Types.color() | t(), keyword()) :: t()
Defines the color of an led with some options specified.
The options can be the following:
:offset
: by how many leds sdo we want to offset. needs to be> 0
if it's bigger than the count then the led will be stored, but ignored (but see the description ofset_count/2
). The same note as forlight/2
applies.:repeat
: How often the light should be repeated. It needs to be more than 1, otherwise it wouldn't make sense. In addition the same note as forlight/2
applies.
if you don't specify a list, but only a number as option, then it's the same as specifying the offset.
See Fledex.Leds.leds/0
.
See Fledex.Leds.leds/1
.
See Fledex.Leds.leds/2
.
See Fledex.Leds.leds/3
.
See Fledex.Leds.leds/4
.
Defines a rainbow over the leds. The options that can be specified are:
:num_leds
: how many leds should be part of the rainbow (by default all leds):offset
: as from which led we want to start the rainbow (default: 0, no offset):reversed
: The rainbow can go from red (start color) to blue (end color) or the other way around.:initial_hue
: The starting color in degree (0..360
). (default: 0)
Note: any led that has been defined before calling this function will be overwritten with the rainbow value.
repeat the existing sequence amount
times
This way you can easily create a repetitive pattern
Note: this will change the led sequence count (amount
times the initial count
)
Convenience function to send the led sequence to an Fledex.LedStrip
.
In order for the function to succeed either set_led_strip_info/3
needs to be
called or the information needs to be passed as part of the opts. The opts can
be the following:
:offset
: Move the led sequence to the side (see Note below):rotate_left
: whether the offset should be appiled toward the right or the left:server_name
: The name of the server_name to which the led sequence should be send to (default:Fledex.LedStrip
):namespace
: The name of the namespace within the LedStrip (default::default
)
Note: the led sequence will always be applied in it's entirety, and will wrap around.
Through the :offset
it is possible to create simple animations by simply counting up
the counter.
@spec set_count(t(), pos_integer()) :: t()
This function sets the count of leds of the led sequence.
Note: Be careful if you redefine the count when some leds have been defined outside of the previous range; they might suddenly become visible.
Define the server_name and the namespace
This is used when the led sequence is sent to the Fledex.LedStrip
when the
send/2
function is called.
Convert the sequence of leds to a binary sequence of Fledex.Color.Types.colorint
colors.
Note: Only the leds that are inside the count
will be emitted into the binary sequence.
@spec to_list(t()) :: [Fledex.Color.Types.colorint()]
Convert the sequence of leds into an list of Fledex.Color.Types.colorint
colors.
Note: Only the leds that are inside the count
will be added to the list.
Convert the sequence of leds to a markdown representation.
The █ will be used to represent the leds and they will be colored in the appropriate color. It then looks something like this:
███The opts are currently not used, but are planned to
be used for potential color correction (similar to Fledex.Driver.Impl.Kino
)