Last active
January 23, 2021 00:57
-
-
Save sandeepmistry/3644150170a87a5df4d37e42c000a10d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import time | |
from machine import Pin | |
led = Pin(25, Pin.OUT) | |
MORSE = { | |
'A': [ '.', '-' ], | |
'B': [ '-', '.', '.', '.' ], | |
'C': [ '-', '.', '-', '.' ], | |
'D': [ '-', '.', '.' ], | |
'E': [ '.' ], | |
'F': [ '.', '.', '-', '.' ], | |
'G': [ '-', '-', '.' ], | |
'H': [ '.', '.', '.', '.' ], | |
'I': [ '.', '.' ], | |
'J': [ '.', '-', '-', '-' ], | |
'K': [ '-', '.', '-' ], | |
'L': [ '.', '-', '.', '.' ], | |
'M': [ '-', '-' ], | |
'N': [ '-', '.'], | |
'O': [ '-', '-', '-' ], | |
'P': [ '.', '-', '-', '.' ], | |
'Q': [ '-', '-', '.', '-' ], | |
'R': [ '.', '-', '.' ], | |
'S': [ '.', '.', '.' ], | |
'T': [ '-' ], | |
'U': [ '.', '.', '-' ], | |
'V': [ '.', '.', '.', '-' ], | |
'W': [ '.', '-', '-' ], | |
'X': [ '-', '.', '.', '-' ], | |
'Y': [ '-', '.', '-', '-' ], | |
'Z': [ '-', '-', '.', '.' ], | |
'1': [ '.', '-', '-', '-', '-' ], | |
'2': [ '.', '.', '-', '-', '-' ], | |
'3': [ '.', '.', '.', '-', '-' ], | |
'4': [ '.', '.', '.', '.', '-' ], | |
'5': [ '.', '.', '.', '.', '.' ], | |
'6': [ '-', '.', '.', '.', '.' ], | |
'7': [ '-', '-', '.' ,'.', '.' ], | |
'8': [ '-', '-', '-', '.', '.' ], | |
'9': [ '-', '-', '-', '-', '.' ], | |
'0': [ '-', '-', '-', '-', '-' ] | |
} | |
UNIT_MS = 200 | |
while True: | |
for c in 'hello world '.upper(): | |
if c == ' ': | |
time.sleep_ms(7 * UNIT_MS) | |
elif c in MORSE: | |
for part in MORSE[c]: | |
led.value(1) | |
if part == '.': | |
time.sleep_ms(1 * UNIT_MS) | |
else: | |
time.sleep_ms(3 * UNIT_MS) | |
led.value(0) | |
time.sleep_ms(3 * UNIT_MS) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment