Page 1 of 1

Text to morse translator

Posted: Sat Nov 28, 2015 2:42 pm
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

Re: Text to morse translator

Posted: Sat Nov 28, 2015 8:34 pm
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.