GrovePi v0.6.1 GrovePi.Poller behaviour View Source
A behaviour module for implementing polling on a pin.
The GrovePi.Poller behavior abstracts polling on a pin. Developers are
responsible for implementing read_value/2
and a module using the
GrovePi.Trigger
behaviour.
Example
This example shows implementation of GrovePi.Potentiometer
. The module
should use GrovePi.Poller
, specifiying the :default_trigger
and
:read_type
. It should have a read_value/2
callback which reads the
desired sensor.
defmodule GrovePi.Potentiometer do
alias GrovePi.Analog
use GrovePi.Poller, default_trigger: GrovePi.Potentiometer.DefaultTrigger,
read_type: Analog.adc_level
def read_value(prefix, pin) do
Analog.read(prefix, pin)
end
end
The requirements for creating the :default_trigger
are described in
GrovePi.Trigger
.