View Source PiGlow.LED (pi_glow v0.1.0)
A structure representing a single LED on a PiGlow device.
These are the values that the PiGlow.map_*
functions pass to the
user-supplied function. Your application code can choose which LEDs to
operate on by looking at the LED's properties:
index
— the position of the LED in the binary versions ofPiGlow.set_enable
andPiGlow.set_power
arm
— which of the three arms the LED is on (clockwise)1
— the top arm, directly below the "PiGlow" text2
— the right arm, on the side with the Pimoroni URL3
— the left arm, on the side with the small text and icons
ring
— how far from the centre the LED is, in the range of1..6
colour
— the LED colour, as an atom
Note that ring
and colour
are effectively the same value, just expressed two different ways:
- ring
1
corresponds to colour:white
- ring
2
corresponds to colour:blue
- ring
3
corresponds to colour:green
- ring
4
corresponds to colour:amber
- ring
5
corresponds to colour:orange
- ring
6
corresponds to colour:red
Additionally, this module also contains utility functions relating to LEDs and LED brightness.
Link to this section Summary
Functions
Calculates the power value needed to approximate a given brightness.
Return the list of LEDs on a PiGlow device.
Link to this section Types
@type colour() :: :white | :blue | :green | :amber | :orange | :red
@type t() :: %PiGlow.LED{arm: 1..3, colour: colour(), index: 1..18, ring: 1..6}
Link to this section Functions
@spec gamma_correct(0..255 | float()) :: 0..255
Calculates the power value needed to approximate a given brightness.
The relationship between how much power is sent to an LED, and how bright that LED actually shines, is a non-linear one — i.e. going from 90% to 95% of max brightness requires a significantly larger increase in energy than going from 5% to 10% of max brightness. This function attempts to correct for that by applying an exponential curve to the supplied brightness value.
The value
argument can be either an integer between 0
and 255
inclusive, or a float between 0.0
and 1.0
inclusive. The result will
follow this pattern:
gamma_correct(v) = 0
whenv
is0
or0.0
gamma_correct(v) = 255
whenv
is255
or1.0
- otherwise,
gamma_correct(v)
will follow an exponential curve from1
to255
Returns an integer in the range of 0..255
, which can be passed to the
power
-based functions in PiGlow
.
examples
Examples
# Pulse all lights once:
iex> [0..255, 255..0] |>
...> Enum.flat_map(&Enum.to_list/1) |>
...> Enum.map(&PiGlow.LED.gamma_correct/1) |>
...> Enum.each(fn value ->
...> PiGlow.map_power(fn _ -> value end)
...> end)
:ok
@spec leds() :: [t()]
Return the list of LEDs on a PiGlow device.
examples
Examples
# Find all green LEDs:
iex> PiGlow.LED.leds() |> Enum.filter(fn led -> led.colour == :green end)
[
%PiGlow.LED{index: 6, arm: 1, ring: 3, colour: :green},
%PiGlow.LED{index: 14, arm: 2, ring: 3, colour: :green},
%PiGlow.LED{index: 4, arm: 3, ring: 3, colour: :green}
]