Hardware components | ||||||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 4 | |||
Software apps and online services | ||||||
![]() |
|
SinceChildhood the day I watched titanic I was wondering what is Morse code, how people contact trans-Atlantic between the oceans. I researched a little bit but then I came to know that it's a historic technique which know can only be seen on the internet
Thanks to the BOLT-IoT and the python training through the course instead of searching for Morse's Transmitter I made one!
Morse Code Encrypt-er, and Transmitter!
PythonI have approached the solution in OOPs way (object-oriented Programming) I wrote a function
1. To Convert English to Morse
2. To Transmit the Morse Code to The LED or The Buzzer
3, Morse code is a language of Dashes and Dots so I wrote a function to transmit a dot, dash and even the space between words
I have added an interactive way for the output so the user won't get bored and try the program multiple times, it asks whether to transmit on LED or on the Buzzer
This is the python code that's connected to my BOLT! with asks the user for input in English and converts it to Morse i.e Dots and Dashes! I programmed it to transmit the code in both ways, visually using LED and Audio via Buzzer! the only drawback the program consists is the one that morse code gives 'time' it takes 10 seconds on average for a single word, but enthusiasts like me watch it with a big smile!
1. To Convert English to Morse
2. To Transmit the Morse Code to The LED or The Buzzer
3, Morse code is a language of Dashes and Dots so I wrote a function to transmit a dot, dash and even the space between words
I have added an interactive way for the output so the user won't get bored and try the program multiple times, it asks whether to transmit on LED or on the Buzzer
This is the python code that's connected to my BOLT! with asks the user for input in English and converts it to Morse i.e Dots and Dashes! I programmed it to transmit the code in both ways, visually using LED and Audio via Buzzer! the only drawback the program consists is the one that morse code gives 'time' it takes 10 seconds on average for a single word, but enthusiasts like me watch it with a big smile!
import time
import requests
MORSE_CODE_DICT = {'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': '-----', ',': '--..--', '.': '.-.-.-',
'?': '..--..', '/': '-..-.', '-': '-....-',
'(': '-.--.', ')': '-.--.-'
}
on = 'https://cloud.boltiot.com/remote/ce212d1c-376b-4b49-b232-XXXX/digitalWrite?pin=0&state=HIGH&deviceName=BOLTXXXXXX'
off = 'https://cloud.boltiot.com/remote/ce212d1c-376b-4b49-b232-XXXX/digitalWrite?pin=0&state=LOW&deviceName=BOLTXXXXXX'
onL = 'https://cloud.boltiot.com/remote/ce212d1c-376b-4b49-b232-XXXX/digitalWrite?pin=1&state=HIGH&deviceName=BOLTXXXXXX'
offL = 'https://cloud.boltiot.com/remote/ce212d1c-376b-4b49-b232-XXXX/digitalWrite?pin=1&state=LOW&deviceName=BOLTXXXXXX'
ans = ''
# HARDWARE FUNCTIONS BUZZING, BLINKING, ETC.
def dot(x):
if x == 0:
requests.get(on)
requests.get(off)
elif x == 1:
requests.get(onL)
requests.get(offL)
def dash(x):
if x == 0:
requests.get(on)
time.sleep(1)
requests.get(off)
elif x == 1:
requests.get(onL)
time.sleep(1.5)
requests.get(offL)
def space():
time.sleep(2)
# CONVERTING ENGLISH TO MORSE CODE
def convert(message):
message = message.upper()
my_cipher = ''
for myletter in message:
if myletter != ' ':
my_cipher += MORSE_CODE_DICT[myletter] + ' '
else:
my_cipher += ' '
return my_cipher
# TRANSMISSION - TRANSMITTING OUR MESSAGE TO THE DEVICE
def led(message):
try:
for i in message:
if i == '.':
dot(1)
elif i == '-':
dash(1)
elif i == ' ':
space()
except:
print('Error')
def buzz(message):
try:
for i in message:
if i == '.':
dot(0)
elif i == '-':
dash(0)
elif i == ' ':
space()
except:
print('Error')
# FINAL OUTPUT -- I know it looks mess but i tried hard on
# making the output beautiful!
# FUNCTIONS TO MAKE OUTPUT INTERACTIVE
def wait(seconds):
time.sleep(seconds)
def printdots(x):
for i in range(2):
print('.')
wait(1)
def printspaces(x):
for i in range(2):
print(' ')
wait(1)
printspaces(2)
print('Hello, welcome to the Morse Magic Show')
wait(1)
print('"They say, if the world goes on war,')
wait(1)
print('Morse code will keep us united"')
printspaces(2)
print('Enter The String you want to convert?')
wait(1)
string = input(
'Include Alphabets, Numbers and .,?/-() These characters only \n')
wait(1)
printdots(2)
print('Converting')
printdots(2)
yes = input('Should i transmit the code to BOLT?(Y/N)\n')
wait(1)
yes = yes.upper()
ans = convert(string)
if yes == 'Y':
printdots(1)
print('Transmiting')
printdots(2)
ques = input(
'oh! wait you wanna see it or hear it? Type:\n 1 for Buzzer! \n 2 for LED! \n')
printdots(2)
print('The show begins !!!')
if ques == '1':
buzz(ans)
elif ques == '2':
led(ans)
else:
wait(1)
print('Duh! Too boring')
wait(1)
print(ans)
Comments