GrovePi v0.3.2 GrovePi.Button View Source

Listen for events from a GrovePi button. There are two types of events by default; pressed and released. When registering for an event the button will then send a message of {pin, :pressed, %{value: 1} or {pin, :released, %{value: 0}}. The button works by polling GrovePi.Digital on the pin that you have registered to a button.

Example usage:

iex> {:ok, button} = GrovePi.Button.start_link(3)
:ok
iex> GrovePi.Button.subscribe(3, :pressed)
:ok
iex> GrovePi.Button.subscribe(3, :released)
:ok

Link to this section Summary

Link to this section Functions

Link to this function change_polling(pin, interval, prefix \\ Default) View Source
change_polling(GrovePi.pin, integer, atom) :: :ok

Stops the current scheduled polling event and starts a new one with the new interval.

Callback implementation for GrovePi.Poller.read_value/2.

Link to this function start_link(pin, opts \\ []) View Source

Options

  • :poll_interval - The time in ms between polling for state.i If set to 0 polling will be turned off. Default: 100
  • :trigger - This is used to pass in a trigger to use for triggering events. See specific poller for defaults
  • :trigger_opts - This is used to pass options to a trigger init1. The default is []
Link to this function stop_polling(pin, prefix \\ Default) View Source
stop_polling(GrovePi.pin, atom) :: :ok

Stops polling immediately

Link to this function subscribe(pin, event, prefix \\ Default) View Source
subscribe(GrovePi.pin, GrovePi.Trigger.event, atom) ::
  {:ok, pid} |
  {:error, {:already_registered, pid}}