GrovePi v0.3.2 GrovePi.DHT11 View Source
Listen for events from a GrovePi DHT (Digital Humidity and Temparature)
sensor. This module is configured for the DHT11, the blue one, that comes
with the GrovePi+ Starter Kit. There is only one type of event by default;
:changed
. When registering for an event the DHT11 will send a message in the
form of {pin, :changed, %{temp: 11.3, humidity: 45.5}
with the temp and
humidty being floats. The GrovePi.DHT11
module works by polling
the pin that you have registered to a DHT sensor.
Example usage:
iex> {:ok, dht} = GrovePi.DHT11.start_link(7)
:ok
iex> GrovePi.DHT11.subscribe(7, :changed)
:ok
The GrovePi.DHT11.DefaultTrigger
is written so when the value of
the either the temp or humidity changes, the subscribed process will receive
a message in the form of {pid, :changed, %{temp: 11.3, humidity: 45.5}
. The
message should be received using GenServer handle_info/2.
For example:
def handle_info({_pid, :changed, %{temp: temp, humidity: humidity}}, state) do
# do something with temp and/or humidity
{:noreply, state}
end
Link to this section Summary
Functions
Stops the current scheduled polling event and starts a new one with the new interval
Callback implementation for GrovePi.Poller.read_value/2
Options
Stops polling immediately
Link to this section Functions
change_polling(GrovePi.pin, integer, atom) :: :ok
Stops the current scheduled polling event and starts a new one with the new interval.
read(GrovePi.pin, atom) :: Digital.level
Callback implementation for GrovePi.Poller.read_value/2
.
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 triggerinit1
. The default is[]
stop_polling(GrovePi.pin, atom) :: :ok
Stops polling immediately
subscribe(GrovePi.pin, GrovePi.Trigger.event, atom) :: {:ok, pid} | {:error, {:already_registered, pid}}