QB64.org Forum
Active Forums => Programs => Topic started by: Bert22306 on December 08, 2021, 07:37:11 pm
-
An ASCII string is split up into individual characters, including spaces, and converted to Morse code. Including audio.
One subroutine converts to Morse, and another one decodes the dots and dashes back to text and numerals.
(Oh shucks. The accented u is meant to be a dot, character 249, in the IBM extended character set. It's a dot at the same elevation as the - sign. I use character 249 as dit, and the - symbol as dah. It shows up fine in QB64.)
Rem Program converts text
to Morse code
, including
sound, then decodes.
_Title "Morse code encoder/decoder" Dim Shared char
(500), MorseChar$
(500), Astring$
, NumBytes
1 Input "Continue or exit (x exits) -> ", cont$
Input "Press <enter> to decode -> ", cont$
Input "Enter string of letters and numbers to convert to Morse code -> ", Astring$
char
(i
) = Asc(Astring$
, i
) Print "There was no input data identified. At least one input byte required." Print "Number of bytes ="; NumBytes
MorseChar$(i) = "*"
Print MorseChar$
(i
), "No Morse equivalent" Rem parentheses
, slash
, + and - signs
MorseChar$(i) = "*"
Print MorseChar$
(i
), "No Morse equivalent" Rem colon
, semicolon
, >, <, ?, etc.
MorseChar$(i) = "*"
Print MorseChar$
(i
), "No Morse equivalent" Rem brackets
, backslash
, etc.
MorseChar$(i) = "*"
Print MorseChar$
(i
), "No Morse equivalent" Rem more brackets
, extended ASCII set
MorseChar$(i) = "*"
Print MorseChar$
(i
), "No Morse equivalent" MorseChar$(i) = " "
MorseChar$(i) = "ù-"
MorseChar$(i) = "-ùùù"
MorseChar$(i) = "-ù-ù"
MorseChar$(i) = "-ùù"
MorseChar$(i) = "ù"
MorseChar$(i) = "ùù-ù"
MorseChar$(i) = "--ù"
MorseChar$(i) = "ùùùù"
MorseChar$(i) = "ùù"
MorseChar$(i) = "ù---"
MorseChar$(i) = "-ù-"
MorseChar$(i) = "ù-ùù"
MorseChar$(i) = "--"
MorseChar$(i) = "-ù"
MorseChar$(i) = "---"
MorseChar$(i) = "ù--ù"
MorseChar$(i) = "--ù-"
MorseChar$(i) = "ù-ù"
MorseChar$(i) = "ùùù"
MorseChar$(i) = "-"
MorseChar$(i) = "ùù-"
MorseChar$(i) = "ùùù-"
MorseChar$(i) = "ù--"
MorseChar$(i) = "-ùù-"
MorseChar$(i) = "-ù--"
MorseChar$(i) = "--ùù"
MorseChar$(i) = "-----"
MorseChar$(i) = "ù----"
MorseChar$(i) = "ùù---"
MorseChar$(i) = "ùùù--"
MorseChar$(i) = "ùùùù-"
MorseChar$(i) = "ùùùùù"
MorseChar$(i) = "-ùùùù"
MorseChar$(i) = "--ùùù"
MorseChar$(i) = "---ùù"
MorseChar$(i) = "----ù"
Rem control codes
, punctuation
, slashes
, extended ASCII
If MorseChar$
(i
) = "*" Then Print MorseChar$
(i
);
" decoded", "InvalidCode" If MorseChar$
(i
) = "ù-" Then Print MorseChar$
(i
);
" decoded", "A" If MorseChar$
(i
) = "-ùùù" Then Print MorseChar$
(i
);
" decoded", "B" If MorseChar$
(i
) = "-ù-ù" Then Print MorseChar$
(i
);
" decoded", "C" If MorseChar$
(i
) = "-ùù" Then Print MorseChar$
(i
);
" decoded", "D" If MorseChar$
(i
) = "ù" Then Print MorseChar$
(i
);
" decoded", "E" If MorseChar$
(i
) = "ùù-ù" Then Print MorseChar$
(i
);
" decoded", "F" If MorseChar$
(i
) = "--ù" Then Print MorseChar$
(i
);
" decoded", "G" If MorseChar$
(i
) = "ùùùù" Then Print MorseChar$
(i
);
" decoded", "H" If MorseChar$
(i
) = "ùù" Then Print MorseChar$
(i
);
" decoded", "I" If MorseChar$
(i
) = "ù---" Then Print MorseChar$
(i
);
" decoded", "J" If MorseChar$
(i
) = "-ù-" Then Print MorseChar$
(i
);
" decoded", "K" If MorseChar$
(i
) = "ù-ùù" Then Print MorseChar$
(i
);
" decoded", "L" If MorseChar$
(i
) = "--" Then Print MorseChar$
(i
);
" decoded", "M" If MorseChar$
(i
) = "-ù" Then Print MorseChar$
(i
);
" decoded", "N" If MorseChar$
(i
) = "---" Then Print MorseChar$
(i
);
" decoded", "O" If MorseChar$
(i
) = "ù--ù" Then Print MorseChar$
(i
);
" decoded", "P" If MorseChar$
(i
) = "--ù-" Then Print MorseChar$
(i
);
" decoded", "Q" If MorseChar$
(i
) = "ù-ù" Then Print MorseChar$
(i
);
" decoded", "R" If MorseChar$
(i
) = "ùùù" Then Print MorseChar$
(i
);
" decoded", "S" If MorseChar$
(i
) = "-" Then Print MorseChar$
(i
);
" decoded", "T" If MorseChar$
(i
) = "ùù-" Then Print MorseChar$
(i
);
" decoded", "U" If MorseChar$
(i
) = "ùùù-" Then Print MorseChar$
(i
);
" decoded", "V" If MorseChar$
(i
) = "ù--" Then Print MorseChar$
(i
);
" decoded", "W" If MorseChar$
(i
) = "-ùù-" Then Print MorseChar$
(i
);
" decoded", "X" If MorseChar$
(i
) = "-ù--" Then Print MorseChar$
(i
);
" decoded", "Y" If MorseChar$
(i
) = "--ùù" Then Print MorseChar$
(i
);
" decoded", "Z" If MorseChar$
(i
) = "-----" Then Print MorseChar$
(i
);
" decoded", "0" If MorseChar$
(i
) = "ù----" Then Print MorseChar$
(i
);
" decoded", "1" If MorseChar$
(i
) = "ùù---" Then Print MorseChar$
(i
);
" decoded", "2" If MorseChar$
(i
) = "ùùù--" Then Print MorseChar$
(i
);
" decoded", "3" If MorseChar$
(i
) = "ùùùù-" Then Print MorseChar$
(i
);
" decoded", "4" If MorseChar$
(i
) = "ùùùùù" Then Print MorseChar$
(i
);
" decoded", "5" If MorseChar$
(i
) = "-ùùùù" Then Print MorseChar$
(i
);
" decoded", "6" If MorseChar$
(i
) = "--ùùù" Then Print MorseChar$
(i
);
" decoded", "7" If MorseChar$
(i
) = "---ùù" Then Print MorseChar$
(i
);
" decoded", "8" If MorseChar$
(i
) = "----ù" Then Print MorseChar$
(i
);
" decoded", "9"
-
An ASCII string is split up into individual characters, including spaces, and converted to Morse code. Including audio.
This is really cool!
Here's an idea for v2, related to @SMcNeill 's suggestion for @SpriggsySpriggs 's API project
https://www.qb64.org/forum/index.php?topic=4468.0 (https://www.qb64.org/forum/index.php?topic=4468.0), of getting input from a microphone:
have it be able to decode actual Morse audio by listening with the microphone!
Theoretically we could get 2 PCs sitting side by side beeping away and "talking" to each other in Morse. :-D
-
Yes, that's exactly what I wanted to do next, but first I need a mic. I'll look to see what Steve and Spriggsy concocted. And to work right, it would have to accommodate a certain amount of slop in length, spacing, and frequencies of the tone.
-
Yes, that's exactly what I wanted to do next, but first I need a mic. I'll look to see what Steve and Spriggsy concocted. And to work right, it would have to accommodate a certain amount of slop in length, spacing, and frequencies of the tone.
Sounds good. Maybe make the program generate Morse code _with_ a certain amount of "slop" to simulate a human sending a message.
Maybe have it display a text window showing a scrolling feed of messages sent & received (in 2 different colors).
Will it know any special codes for protocol, like "over" telling the other system it's done sending and will now listen?
This could be a great learning tool also, you can drill on one letter a day, or review & it will test you on what you've learned.
Back to the demo of 2 PCs beeping back and forth, I'm reminded of stuff like this where 2 chatbots hold a conversation:
https://youtu.be/PTUY16CkS-k (https://youtu.be/PTUY16CkS-k)
It would be a funny demo for the 2 PCs communicating in Morse code to be chatbots or Eliza programs trying to hold a conversation. You would hear beeping back & forth but could follow the conversation in the text window.
Just some ideas... Just a program that can listen and interpret Morse code from audio would be pretty cool!
-
word compatible macros is more logical for mass replacement
and macro includes constructions:
dim data read for to next replace
-
Yes, that's exactly what I wanted to do next, but first I need a mic. I'll look to see what Steve and Spriggsy concocted. And to work right, it would have to accommodate a certain amount of slop in length, spacing, and frequencies of the tone.
I just thought I would follow up and see if you ever got around to enabling the program to "hear" Morse code through a mic?