View Source grisp_led (grisp v2.8.0)

Summary

Functions

Set the color of an LED.

Flash an LED in an on/off pattern with the specified color.

Turn off an LED.

Animate an LED with a pattern of colors and intervals.

Types

color()

-type color() :: color_name() | color_value().

color_name()

-type color_name() :: off | black | blue | green | aqua | red | magenta | yellow | white.

color_value()

-type color_value() :: {0 | 1, 0 | 1, 0 | 1}.

pattern()

-type pattern() :: [{time(), color() | fun(() -> color())}].

position()

-type position() :: 1 | 2.

time()

-type time() :: pos_integer() | infinity.

Functions

color(Pos, Color)

-spec color(position(), color()) -> ok.

Set the color of an LED.

Examples

1> grisp_led:color(1, red).
ok
2> grisp_led:color(2, {0, 1, 0}).
ok

flash(Pos, Color, Interval)

-spec flash(position(), color(), time()) -> ok.

Flash an LED in an on/off pattern with the specified color.

Examples

1> grisp_led:flash(2, blue, 500).
ok

off(Pos)

-spec off(position()) -> ok.

Turn off an LED.

pattern(Pos, Pattern)

-spec pattern(position(), pattern()) -> ok.

Animate an LED with a pattern of colors and intervals.

Examples

1> grisp_led:pattern(1, [{300, green}, {500, yellow}, {700, red}, {infinity, off}]).
ok
2> Rainbow = [{300, {R, G, B}} || R <- [0,1], G <- [0,1], B <- [0,1], {R, G, B} =/= {0, 0, 0}].
[{300,{0,0,1}},
 {300,{0,1,0}},
 {300,{0,1,1}},
 {300,{1,0,0}},
 {300,{1,0,1}},
 {300,{1,1,0}},
 {300,{1,1,1}}]
3> grisp_led:pattern(2, Rainbow).
ok

The color can also be specified using functions as generators instead of explicitly stating the color :

2> Random = fun() -> {rand:uniform(2) - 1, rand:uniform(2) -1, rand:uniform(2) - 1} end.
#Fun<erl_eval.20.128620087>
3> grisp_led:pattern(1, [{100, Random}]).

As well as by composing lists of intervals and pattern functions :

4> Funs = [ fun() -> {X rem 2, rand:uniform(2) - 1 , 1} end || X <- lists:seq(1,10) ].
[#Fun<erl_eval.20.128620087>, ...
5> Intervals = lists:seq(1000,1900,100).
[1000,1100,1200,1300,1400,1500,1600,1700,1800,1900]
6> Result = lists:zip(Intervals, Funs).
[{1000,#Fun<erl_eval.20.128620087>},...
7> grisp_led:pattern(1, Result).

read(Pos)