Last active
April 11, 2017 17:24
-
-
Save ChristopheBelpaire/3c94a7ec58ff57b2f3a219aca5d15830 to your computer and use it in GitHub Desktop.
And example of genserver using ElixirAle with set_int interruptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule GpioInput do | |
use GenServer | |
@item_in_pin 17 | |
def start_link() do | |
GenServer.start_link(__MODULE__, [], []) | |
end | |
def init(_) do | |
{:ok, pid} = ElixirALE.GPIO.start_link(@item_in_pin, :input) | |
ElixirALE.GPIO.set_int(pid, :both) | |
{:ok, pid} | |
end | |
def handle_info({:gpio_interrupt, @item_in_pin, :rising}, state) do | |
IO.puts("rinsing") | |
{:noreply, state} | |
end | |
def handle_info({:gpio_interrupt, @item_in_pin, :falling}, state) do | |
IO.puts("falling") | |
{:noreply, state} | |
end | |
def handle_cast(_, state) do | |
IO.puts("error") | |
{:reply, state} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment