Skip to content

BrightPi is an Elixir library to talk to the "Pi Supply Bright Pi" LED board

License

Notifications You must be signed in to change notification settings

PhillippOhlandt/bright_pi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BrightPi

Test Status Latest Version

BrightPi is a library to talk to the Pi Supply Bright Pi board featuring 4 white LEDs and 4 pairs of two infrared LEDs.

This library can control the on/off value of each LED or LED pair, as well as their dim value and a global gain value.

Examples

# Turn all white LEDs on
iex> BrightPi.set_leds([1, 2, 3, 4])
{:ok, [1, 2, 3, 4]}

# Turn all infrared LEDs on
iex> BrightPi.set_leds([5, 6, 7, 8])
{:ok, [5, 6, 7, 8]}

# Dim some LEDs
iex> BrightPi.set_leds_dim([1, 2, 3, 4], 10)
{:ok, [10, 10, 10, 10, 1, 1, 1, 1]}

# Set gain for all LEDs
iex> BrightPi.set_gain(10)
{:ok, 10}

Installation

The package can be installed by adding bright_pi to your list of dependencies in mix.exs:

def deps do
  [
    {:bright_pi, "~> 1.0"}
  ]
end

Setup

In order to use the library, the board process needs to be added to the supervision tree.

defmodule MyApp.Application do
  use Application

  @impl true
  def start(_type, _args) do
    children = [
      BrightPi.board()
    ]
    
    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

By default, the BrightPi.board/0 helper function returns the BrightPi.Board module which talks to the real LED board over I2C.

For local development, the BrightPi.VirtualBoard module can be configured via application configuration:

# config/host.exs

config :bright_pi, board: BrightPi.VirtualBoard

The BrightPi.VirtualBoard module mocks all the functionality of the real LED board.

Depending on the application setup, each board can also be started explicitly in the supervision tree, as long as the proper board is set via configuration in each environment.

The whole documentation can be found at https://hexdocs.pm/bright_pi.