from machine import Pin
from time import sleep
led = Pin(5, Pin.OUT) 

timeunit = 0.12 
#Xalqaro Morze kodiga muvofiq nisbatlar:
dit = timeunit
dah = timeunit*3
cspace = timeunit*3
wspace = timeunit*7

alphaturple = (".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..")
numberturple = ("-----",".----","..---","...---","....-",".....","-....","--...","---..","----.")

stringtoconvert = "Bu 2-sinov"

def sendchar(morse): 
    print (c + " " + morse)
    for x in morse:
        led.value(1)
        if x == ".":
            sleep(dit)
        elif x == "-":
            sleep(dah)
        led.value(0)
        sleep(dit)

print(stringtoconvert)
ucstring = stringtoconvert.upper() #bosh harfga aylantirish
print(ucstring)
print("Xabarni yuborish...")
sleep(2)
for c in ucstring: #bosh harflar qatorimiz orqali takrorlang
    charascii = ord(c) #ascii char kodini olish
    if 65 <= charascii <= 90: 
        thechar = alphaturple[charascii-65] #'cos A = ascii 65,
        sendchar(thechar) 
        sleep(cspace) #belgilar orasidagi bo'shliq
    if 48 <= charascii <= 57: #raqamlar bilan ishlash
        thechar = numberturple[charascii-48] #'cos 0 = ascii 48
        sendchar(thechar) 
        sleep(cspace) #belgilar orasidagi bo'shliq      
    if charascii == 32:
        print(" ")
        sleep(wspace) #so'zlar orasidagi bo'shliq
print("Xabar yuborildi.")
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT