Last active
April 1, 2020 13:35
-
-
Save oschettler/077844b88fd3223d92ac1e42bc9e42b3 to your computer and use it in GitHub Desktop.
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
# Morse a text | |
# https://en.wikipedia.org/wiki/Morse_code | |
from gpiozero import LED | |
from time import sleep | |
led = LED(17) | |
# the higher this number, the slower the blinking | |
speed = 2 | |
#text = 'sos' | |
text = 'hello world' | |
morsecode = { | |
'h': '....', | |
'e': '.', | |
'l': '.-..', | |
'o': '---', | |
'w': '.--', | |
'r': '.-.', | |
'd': '-..', | |
's': '...', | |
} | |
def blink(char): | |
code = morsecode[char] | |
for c in code: | |
len = 0.1 if c == '.' else 0.3 | |
led.on() | |
sleep(len * speed) | |
led.off() | |
sleep(0.1 * speed) | |
sleep(0.2 * speed) | |
for c in text: | |
if c == ' ': | |
sleep(0.7 * speed) | |
else: | |
print("Binking", c) | |
blink(c) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment