Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChristopheBelpaire/3c94a7ec58ff57b2f3a219aca5d15830 to your computer and use it in GitHub Desktop.
Save ChristopheBelpaire/3c94a7ec58ff57b2f3a219aca5d15830 to your computer and use it in GitHub Desktop.
And example of genserver using ElixirAle with set_int interruptions
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