I'm writing a small morse code translator.
But for some reason, it's not working.
For some reason, the broadcasting part is not working... I can't get it. Any help is welcome !
Here is the code:
#import RPi.GPIO as GPIO
import re,time, pdb
def get_user_text():
user_text = raw_input("Please enter the message you would lile to broadcast. >> ")
user_text = user_text.lower()
word_list = list(user_text)
return word_list
def text_to_morse_code(alpha_text):
morse_code = []
for letter in alpha_text:
if letter == "a" or letter == "à" or letter == "â" or letter == "ä":
morse_code.append("01")
if letter == "b":
morse_code.append("1000")
if letter == "c":
morse_code.append("1010")
if letter == "d":
morse_code.append("100")
if letter == "e" or letter == "è" or letter == "é" or letter == "ê":
morse_code.append("0")
if letter == "f":
morse_code.append("0010")
if letter == "g":
morse_code.append("110")
if letter == "h":
morse_code.append("0000")
if letter == "i" or letter == "î" or letter == "ï":
morse_code.append("00")
if letter == "j":
morse_code.append("0111")
if letter == "k":
morse_code.append("101")
if letter == "l":
morse_code.append("0100")
if letter == "m":
morse_code.append("11")
if letter == "n":
morse_code.append("10")
if letter == "o":
morse_code.append("111")
if letter == "p":
morse_code.append("0110")
if letter == "q":
morse_code.append("1101")
if letter == "r":
morse_code.append("010")
if letter == "s":
morse_code.append("111")
if letter == "t":
morse_code.append("0")
if letter == "u":
morse_code.append("001")
if letter == "v":
morse_code.append("0001")
if letter == "w":
morse_code.append("011")
if letter == "x":
morse_code.append("1001")
if letter == "y":
morse_code.append("1011")
if letter == "z":
morse_code.append("1100")
if letter == ".":
morse_code.append("010101")
if letter == " ":
morse_code.append(" ")
else:
pass
morse_code = ''.join(map(str, morse_code))
morse_code = list(morse_code)
return morse_code
def broadcast_code(code_to_broadcast, pin):
# Set the board as BOARD
#GPIO.setmode(GPIO.BOARD)
print("Set the board to BOARD")
# Setup the n th pin to OUTPUT
#GPIO.setup(pin, GPIO.OUT)
print("Set the "+str(pin)+"th to OUTPUT")
# Starting the broadcast
print("Starting Broadcast")
start_broadcast = [0,1,0,1]
for number in start_broadcast:
if number == 1:
#GPIO.output(pin,True)
time.sleep(1)
#GPIO.output(pin, False)
print(number)
if number == 0:
#GPIO.output(pin,True)
time.sleep(0.5)
#GPIO.output(pin, False)
print(number)
print("Broadcasting")
code_to_broadcast = code_to_broadcast
for number in code_to_broadcast:
if number == 1:
#GPIO.output(pin,True)
time.sleep(1)
#GPIO.output(pin, False)
print(number)
if number == 0:
#GPIO.output(pin,True)
time.sleep(0.5)
#GPIO.output(pin, False)
print(number)
#Boardcast end of transmission.
print("Ending Boardcast")
end_broadcast = [0,0,0,1,0,1]
for number in end_broadcast:
if number == 1:
#GPIO.output(pin,True)
time.sleep(1)
#GPIO.output(pin, False)
print(number)
if number == 0:
#GPIO.output(pin,True)
time.sleep(0.5)
#GPIO.output(pin, False)
print(number)
#GPIO.cleanup()
print("Cleaned up the board.")
def get_code_broadcast():
#
#GPIO.output(pin,True)
print("Hello")
if __name__ == '__main__':
code = get_user_text()
code = text_to_morse_code(code)
broadcast_code(code,7)
And the output I get :
$ Please enter the message you would lile to broadcast. >> Hello
Set the board to BOARD
Set the 7th to OUTPUT
Starting Broadcast
0
1
0
1
Broadcasting
Ending Boardcast
0
0
0
1
0
1
Cleaned up the board.
ifblock that is 26 levels , you couldve just used adict.