TSL256X (tsl256x v0.1.1)

Copy Markdown View Source

Documentation for TSL256x family of Ligh to digital convertors.

This module supports TSL2560 and 2561 in both T and SC packages.

To start add the module to your mix.exs

Summary

Functions

Disable the sensor

Enable the sensor

Checks to see if the sensor is currently enabled.

Gets the current gain setting from the sensor

Sets the current gain setting for the sensor

Gets the current integration time from the sensors.

Set the integration time, check integration_time/1 for the possible values.

Calculate the current light strength in lux.

Start the sensor and return a struct for future calls.

Stop the light sensor and closes the I2C bus.

Types

t()

@type t() :: %TSL256X{bus_ref: term(), rev: term(), type: term()}

Functions

disable(sensor)

@spec disable(t()) :: :ok | {:error, any()}

Disable the sensor

enable(sensor)

@spec enable(t()) :: :ok | {:error, any()}

Enable the sensor

enabled?(sensor)

@spec enabled?(t()) :: true | false | {:error, any()}

Checks to see if the sensor is currently enabled.

gain(sensor)

@spec gain(t()) :: 0 | 1

Gets the current gain setting from the sensor:

  • 0 - 1X
  • 1 - 16X

gain(sensor, value)

@spec gain(t(), 0 | 1) :: :ok | {:error, any()}

Sets the current gain setting for the sensor:

  • 0 - 1X
  • 1 - 16X

integration_time(sensor)

@spec integration_time(t()) :: 0 | 1 | 2 | 3 | {:error, any()}

Gets the current integration time from the sensors.

valuescalenominal integration time
00.03413.7 ms
10.252101 ms
21402 ms
3--N/A

When the value is set to 3, manual timing control is used, check the datasheet for more information.

integration_time(sensor, value)

@spec integration_time(t(), 0..3) :: :ok | {:error, any()}

Set the integration time, check integration_time/1 for the possible values.

lux(sensor)

Calculate the current light strength in lux.

Example

   iex> TSL256X.lux(sensor)
   2851

start(i2c_bus, retries \\ 1)

@spec start(String.t(), integer()) :: {:ok, t()} | {:error, any()}

Start the sensor and return a struct for future calls.

Examples

iex> TSL256X.start("i2c-1", 4)
{:ok, %TSL256X{}}

stop(sensor)

@spec stop(t()) :: :ok

Stop the light sensor and closes the I2C bus.

Examples

iex> TSL256X.stop(sensor)
:ok