Created
March 7, 2020 22:51
-
-
Save bettio/62e378d09aaf6d604f15802f4f76ddef to your computer and use it in GitHub Desktop.
Elixir morse encoder example - step 6
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
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