Skip to content

Instantly share code, notes, and snippets.

@oschettler
Last active April 1, 2020 13:35
Show Gist options
  • Save oschettler/077844b88fd3223d92ac1e42bc9e42b3 to your computer and use it in GitHub Desktop.
Save oschettler/077844b88fd3223d92ac1e42bc9e42b3 to your computer and use it in GitHub Desktop.
# 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