View Source CircuitsSim.Device.GPIOButton (circuits_sim v0.1.0)

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

@type connection_mode() ::
  :external_pullup | :external_pulldown | :internal_pullup | :internal_pulldown
@type options() :: [{:connection, connection_mode()}]
@type t() :: %CircuitsSim.Device.GPIOButton{
  connection: connection_mode(),
  state: :pressed | :released
}

Functions

@spec child_spec(options()) :: %{
  id: CircuitsSim.GPIO.GPIOServer,
  start: {CircuitsSim.GPIO.GPIOServer, :start_link, [[keyword()], ...]}
}
@spec new(options()) :: t()
Link to this function

press(gpio_spec, duration \\ :infinity)

View Source
@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.

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

Release the button