Simple API to drive leds exposed by linux /sys/class/leds
. Designed for use with Nerves, but works on any distribution of Linux with /sys/class/leds
.
Add nerves_leds
to your list of dependencies in mix.exs
:
def deps do
[{:nerves_leds, "~> 0.8.1"}]
end
Configure your LEDs mappings:
# config/config.exs
config :nerves_leds, names: [ error: "led0", connect: "led1" ]
Now, you can use predefined states in your app:
alias Nerves.Leds
Leds.set(connect: true)
Leds.set(connect: :heartbeat)
Leds.set(connect: false, error: :slowblink)
You can also define your own states:
# config/config.exs
config :nerves_leds, states: [
fastblink: [ trigger: "timer", delay_off: 40, delay_on: 30 ],
blip: [ trigger: "timer", delay_off: 1000, delay_on: 100 ]]
For situations where the number of LEDs are not known at compile time, you can enumerate the LEDs:
Leds.enumerate()
See the documentation for the full description of the API and configuration.