CircuitsSim.Device.GPIOButton (circuits_sim v0.1.2)

View Source

This is simple GPIO-connected button

Buttons can be connected in a few ways:

  • :external_pullup - 0 is pressed, 1 is released
  • :external_pulldown - 1 is pressed, 0 is released
  • :internal_pullup - 0 is pressed. The GPIO will need to be configured in pullup mode for releases to be 1.
  • :internal_pulldown - 1 is pressed. The GPIO will need to be configured in pulldown mode for releases to be 0.

Call press/1 and release/1 to change the state of the button.

Summary

Types

connection_mode()

@type connection_mode() ::
  :external_pullup | :external_pulldown | :internal_pullup | :internal_pulldown

options()

@type options() :: [{:connection, connection_mode()}]

t()

@type t() :: %CircuitsSim.Device.GPIOButton{
  connection: connection_mode(),
  state: :pressed | :released
}

Functions

child_spec(args)

@spec child_spec(options()) :: %{
  id: CircuitsSim.GPIO.GPIOServer,
  start: {CircuitsSim.GPIO.GPIOServer, :start_link, [[keyword()], ...]}
}

new(options)

@spec new(options()) :: t()

press(gpio_spec, duration \\ :infinity)

@spec press(Circuits.GPIO.gpio_spec(), non_neg_integer() | :infinity) :: :ok

Press the button

Pass in a duration in milliseconds to automatically release the button after a timeout.

release(gpio_spec)

@spec release(Circuits.GPIO.gpio_spec()) :: :ok

Release the button