import random
from machine import Pin
from utime import sleep
dot = 0.25
dash = 1
gap = 0.2
gap_1 = 0.5 # gap between two letters
gap_w = 2 # gap between two words
def dot():
led1.on()
sleep(0.25)
led1.off()
sleep(0.2)
def dash():
led1.on()
sleep(1)
led1.off()
sleep(0.2)
def gap_l():
sleep(0.5)
def gap_w():
sleep(2)
di = {'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':'_____',
'?':'..__..', '!':'_._.__', '.':'._._._', ',':'__',
';':'_._._.', ':':'___...', '+':'._._.', '-':'_...._',
'/':'_.._.', '=':'_..._'}
def get_letter(n): # recieves first input
for i in n: # iterates through each character(i) in sentence
if i != ' ':
get_morsed(di[i.upper()]) # searches the value of the key using get_morsed(i)
print(i,end='') # prints converted character(i) on console
sleep(0.5)
else:
print(i,end='') # space means no blink
sleep(2)
def get_morsed(n): # searches the value of key (i) in dictionary
for i in n: # loops through the character(i) in value
if i == '.':
dot()
elif i == '_':
dash()
led1 = Pin(13, Pin.OUT)
sentence = "s s"
get_letter(sentence)
print()