SSD1306.Device (ssd1306 v1.0.0)

An individual SSD1306 device.

Each device needs it's configuration specified in your application's configuration.

Example configuration:

config :ssd1306,
  devices: [
    %{bus: "i2c-1", address: 0x3D, name: :display0, width: 128, height: 32}
  ]

Note that bus and address are required, width and height are optional and default to 128 and 64 respectively.

name is also optional and allows you to specify an arbitrary name to register this device as in ssd1306's process registry. You can then use this name when using the public functions in this module to refer to a specific device. If not provided then a tuple of the bus name and address will be used, for example the device above would be named {"i2c-1", 0x3D} if the name value had not been set.

Link to this section Summary

Functions

Turn off all pixels of the attached device.

Turn on all pixels of the attached device.

Returns a specification to start this module under a supervisor.

Send the contents of buffer to the device for display.

Send arbitrary commands to the device.

Link to this section Types

@type address() :: non_neg_integer()
@type buffer() :: binary()
@type bus() :: String.t()
Link to this type

device_name()

@type device_name() :: {bus(), address()} | term()

Link to this section Functions

Link to this function

all_off(device_name)

@spec all_off(device_name()) :: :ok | {:error, term()}

Turn off all pixels of the attached device.

Link to this function

all_on(device_name)

@spec all_on(device_name()) :: :ok | {:error, term()}

Turn on all pixels of the attached device.

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

display(device_name, buffer)

@spec display(device_name(), buffer()) :: :ok | {:error, term()}

Send the contents of buffer to the device for display.

Link to this function

execute(device_name, function)

@spec execute(device_name(), function()) :: :ok

Send arbitrary commands to the device.

This is useful for any advanced usage that doesn't involve just sending a buffer to the display.

The function argument is a function which will be called from within the device process with the PID of the I2C connection as it's only argument. Be aware that if this function takes a while to execute the device will be unable to respond to other messages.

The commands are listed in the [SSD1306.Commands] module, and information about them can be found in the SSD1306 Datasheet.

example

Example

To invert the display.

iex> alias SSD1306.{Device, Commands}
...> Device.commands({"i2c-1", 0x3D}, fn pid -> Commands.invert_display!(pid) end)
:ok
Link to this function

initialize_buffer(map, value)