Skip to content

Instantly share code, notes, and snippets.

@bettio
Created March 7, 2020 22:51
Show Gist options
  • Save bettio/62e378d09aaf6d604f15802f4f76ddef to your computer and use it in GitHub Desktop.
Save bettio/62e378d09aaf6d604f15802f4f76ddef to your computer and use it in GitHub Desktop.
Elixir morse encoder example - step 6
defp blink_led(nil, _l) do
:ok
end
defp blink_led(gpio_num, l) do
gpio = get_gpio()
GPIO.set_direction(gpio, gpio_num, :output)
Enum.each(l, fn e ->
case e do
?\s ->
GPIO.set_level(gpio, gpio_num, 0)
:timer.sleep(120)
?. ->
GPIO.set_level(gpio, gpio_num, 1)
:timer.sleep(120)
GPIO.set_level(gpio, gpio_num, 0)
:timer.sleep(120)
?- ->
GPIO.set_level(gpio, gpio_num, 1)
:timer.sleep(120 * 3)
GPIO.set_level(gpio, gpio_num, 0)
:timer.sleep(120)
end
end)
end
defp get_gpio() do
case Process.whereis(:gpio) do
nil ->
gpio = GPIO.open()
Process.register(gpio, :gpio)
gpio
p ->
p
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment