Text to morse translator

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Text to morse translator

Post by Henko »

' Translates a piece of text to a string of morse tokens.
' Next version will output a regular sound stream
'

Code: Select all

dim morse$(123)
morse_init
print text2morse$("Now is the time.")
end

' get the morse code for a piece of text
' space between caracters within a word is one space
' space between words consists of 3 spaces
' no check on permissible caracters
'
def text2morse$(t$)
if t$="" then return t$
last=len(t$)-1 ! m$=""
for i=0 to last
	tok$=mid$(t$,i,1)
  if tok$=" " then m$&="  " else m$&=.morse$(asc(tok$)) & " "
  next i
return m$
end def

' get the morse code for one caracter (token$)
' no check on permissible caracter
def get_morse$(token$) = .morse$(asc(token$))

' initialize the morse table
' permissible caracters can be found in the array :
'    morse_init.tok$() after initialization
' for convenience, lower case caracters are also accepted
'    they get the same code as their upper case companions
'
def morse_init
dim tok$(51),m$(51)
if already_read then return
already_read=1
for i=1 to 50
  read tok$(i),m$(i) ! .morse$(asc(tok$(i)))=m$(i)
  if i<=26 then .morse$(asc(lowstr$(tok$(i))))=m$(i)
  next i
data "A",".-","B","-...","C","-.-.","D","-..","E","."
data "F","..-.","G","--.","H","....","I","..","J",".---"
data "K","-.-","L",".-..","M","--","N","-.","O","---"
data "P",".--.","Q","--.-","R",".-.","S","...","T","-"
data "U","..-","V","...-","W",".--","X","-..-","Y","-.--"
data "Z","--..","0","-----","1",".----","2","..---"
data "3","...--","4","....-","5",".....","6","-...."
data "7","--...","8","---..","9","-...."
data ".",".-.-.-",",","--..--","?","..--..","!","-.-.--"
data "-","-....-","/","-..-.",":","---...","'",".----."
data ")","-.--.-",";","-.-.-","(","-.--.","=","-...-"
data "@",".--.-.","&",".-..."
end def

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Text to morse translator

Post by rbytes »

Thanks for this code. My father was deeply involved in ham radio and built his own transmitters and receivers. We had a tall antenna mast in the back yard. Dad had cards from other ham operators all around the world. I look forward to your sound translator. I will put in my Dad's Morse call sign, CQ CQ VE5UQ VE5UQ, and it will take me back to those years.
The only thing that gets me down is gravity...

Post Reply