import time
import board
import digitalio
from time import sleep
led = digitalio.DigitalInOut(board.GP1) #PIN gp26 Green Led
button = digitalio.DigitalInOut(board.GP27) #Pin button 27
led.direction = digitalio.Direction.OUTPUT #objeto como salida
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.DOWN
#Functions
def dot(): #Function that makes a dot with the led
led.value = True #Turn on the LED
sleep(0.5) #Sleep of 0.5 seconds
led.value = False #Turn off the LED
sleep(0.5) #Sleep of 0.5 seconds
def line(): #Function that makes a line with the led
led.value = True #Turn on the LED
sleep(1) #Sleep of 1 second
led.value = False #Turn off the LED
sleep(0.5) #Sleep of 0.5 seconds
#The loop function runs over and over again forever
while True:
#Read sentence
sentence = input("Write the sentence you want to translate into Morse code \n") #Reads the users input and explain what to do.
print("-------------------------") #Generates a separation
#Translating the sentence
for character in sentence: //Action that will be repeated for each character in the sentence
if character == "A" or character == "a": #Letter num 1 - A
print("A = . _") #Prints the letter and the morse code
dot() #Calls the function "dot" to create a the "." with the led
line() #Calls the function "line" to create a the "'" with the led
elif character == "B" or character == "b": #Letter num 2 - B
print("B = _ . . . ") #Prints the letter and the morse code
line() #Calls the function "line" to create a the "'" with the led
dot() #Calls the function "dot" to create a the "." with the led
dot() #Calls the function "dot" to create a the "." with the led
elif character == "C" or character == "c": #Letter num 3 - C
print("C = _ . _ . ")
line()
dot()
line()
dot()
elif character == "D" or character == "d": #Letter num 4 - D
print("D = _ . . ")
line()
dot()
elif character == "E" or character == "e": #Letter num 5 - E
print("E = . ")
dot()
elif character == "F" or character == "f": #Letter num 6 - F
print("F = _ . . ")
dot()
dot()
line()
dot()
elif character == "G" or character == "g": #Letter num 7 - G
print("G = _ _ . ")
line()
line()
dot()
elif character == "H" or character == "h": #Letter num 8 - H
print("H = . . . . ")
dot()
dot()
dot()
dot()
elif character == "I" or character == "i": #Letter num 9 - I
print("I = . . ")
dot()
dot()
elif character == "J" or character == "j": #Letter num 10 - J
print("J = . - - - ")
dot()
line()
line()
line()
elif character == "K" or character == "k": #Letter num 11 - K
print("K = - . - ")
line()
dot()
line()
elif character == "L" or character == "l": #Letter num 12 - L
print("L = . - . . ")
dot()
line()
dot()
dot()
elif character == "M" or character == "m": #Letter num 13 - M
print("M = - - ")
line()
line()
elif character == "N" or character == "n": #Letter num 14 - N
print("N = - . ")
line()
dot()
elif character == "O" or character == "o": #Letter num 15 - O
print("O = - - - ")
line()
line()
line()
elif character == "P" or character == "p": #Letter num 16 - P
print("P = . - - . ")
dot()
line()
line()
dot()
elif character == "Q" or character == "p": #Letter num 17 - Q
print("Q = - - . - ")
line()
line()
dot()
line()
elif character == "R" or character == "r": #Letter num 18 - R
print("R = . - . ")
line()
dot()
line()
elif character == "S" or character == "s": #Letter num 19 - S
print("S = . . . ")
dot()
dot()
dot()
elif character == "T" or character == "t": #Letter num 20 - T
print("T = - ")
line()
elif character == "U" or character == "u": #Letter num 21 - U
print("U = . . - ")
dot()
dot()
line()
elif character == "V" or character == "v": #Letter num 22 - V
print("V = . . . - ")
dot()
dot()
dot()
line()
elif character == "W" or character == "w": #Letter num 23 - W
print("W = . - - ")
dot()
line()
line()
elif character == "X" or character == "x": #Letter num 24 - X
print("X = - . . - ")
line()
dot()
dot()
line()
elif character == "Y" or character == "y": #Letter num 25 - Y
print("Y = - . - - ")
line()
dot()
line()
line()
elif character == "Z" or character == "z": #Letter num 26 - Z
print("Z = - - . . ")
line()
line()
dot()
dot()
#Special Characters
elif character == " ": #Space
print("Space")
sleep(2)