rotary_encoder v1.0.0 RotaryEncoder View Source
Documentation for RotaryEncoder, a library for using rotary encoders in Elixir.
Encoders can be set up via the config or can be programatically added and deleted at runtime.
config :rotary_encoder, RotaryEncoder,
encoders: [
%{
name: "main"
encoder_a_pin: 22,
encoder_b_pin: 23,
button_pin: 24,
}
]
# or
RotaryEncoder.add_encoder("main", 22, 23, 24)
# and
RotaryEncoder.delete_encoder("main")
Then inside your code just subscribe to that encoder in whatever process need the notification and wait to receive events.
def init(opts) do
RotaryEncoder.subscribe(main)
end
def handle_info({:travel, %{direction: :ccw, value: value}}, socket) do
# react to counter-clockwise rotation
{:noreply, socket}
end
def handle_info({:travel, %{direction: :cw, value: value}}, socket) do
# react to clockwise rotation
{:noreply, socket}
end
def handle_info({:click, %{type: :up, duration: duration}}, socket) do
# react to button up
{:noreply, socket}
end
def handle_info({:click, %{type: :down}}, socket) do
# react to button down
{:noreply, socket}
end
Link to this section Summary
Functions
Begin monitoring the specified encoder pins. The name parameter is required and it must not already be in use.
Returns an array RotaryEncoder.State
structs representing all encoders.
Stop monitoring the pins associated with the named encoder.
Returns true if an encoder with the given name already exists.
Returns a RotaryEncoder.State
struct describing the named encoder.
Returns the value of the named encoder. The value is initiated at zero and incermertned or decremented every time the encoder is turned.
Will reset the value of the named encoder to 0.
Start listening for the named encoders events in the calling thread.
Link to this section Functions
Begin monitoring the specified encoder pins. The name parameter is required and it must not already be in use.
In order for the encoder portion to work both encoder_a_pin and encoder_b_pin parameters must be set. In order for the push button portion (if there is one) the button_pin parameter must be set.
Neither of these options are necessary, the library can monitor a single button, or a rotary encoder without a push button built in. Use nil for paramters you don't want to use.
Returns an array RotaryEncoder.State
structs representing all encoders.
Stop monitoring the pins associated with the named encoder.
Returns true if an encoder with the given name already exists.
Returns a RotaryEncoder.State
struct describing the named encoder.
Will raise if the encoder does not exist.
Returns the value of the named encoder. The value is initiated at zero and incermertned or decremented every time the encoder is turned.
Will raise if the encoder does not exist.
Will reset the value of the named encoder to 0.
Will raise if the encoder does not exist.
Start listening for the named encoders events in the calling thread.