ServoKit.Servo behaviour (servo_kit v0.0.8) View Source

Defines a behaviour required for a servo.

Link to this section Summary

Types

Type that represents a servo command.

Callbacks

Executes the specified command and returns the updated state. A command is made up of

Initializes the servo.

Link to this section Types

Specs

command() :: atom() | {atom(), list()}

Type that represents a servo command.

Specs

config() :: map()

Specs

driver() :: struct()

Specs

state() :: struct()

Link to this section Callbacks

Specs

call(state(), command()) :: {:ok, state()} | {:error, any()} | :no_return

Executes the specified command and returns the updated state. A command is made up of:

  • a command name atom

  • a list of arguments for the command, typically first one is a channel number

    = ServoKit.StandardServo.call(state, {:set_angle, [0, 90]})

Specs

new(driver(), config()) :: state() | :no_return

Initializes the servo.

servo =
  %{i2c_bus: "i2c-1"}
  |> ServoKit.PCA9685.new()
  |> ServoKit.StandardServo.new(%{
    angle_max: 180,
    duty_cycle_minmax: {2.5, 12.5}
  })