Morse Code: it consists of a combination of dots and dashes in standardized sequences. I set
out to write a application in VB.NET that would read Morse Code and translate it
The project turned out a lot more work than I thought it would be. I ended up with a project
which was different than the one I had originally intended. This new project will help you learn Morse Code and can
be used as a beacon.
The biggest problem I had was using a sound control in VB.NET.
Although there is DirectX sound for VB.NET, I considered it far too complex. So I ended up with the beep function.
There are two important things that it
has to do. The beep has to be able to change frequency and duration. The first
thing that you have to do is enable the beep. Using just
results in no adjustment in duration or frequency. This line of code just gets us started. In
the same sub we start the timer for the clock in a textbox to be displayed in the toolbar.
We also set the variable
freq from the
Public Declare Function Beep Lib "kernel32" Alias "Beep" (
ByVal dwFreq As Integer, ByVal dwDuration As Integer) As Integer
freq = TrackBar1.Value
Morse code is all about timing. The timing is set like this.
Points of Interest
After the user has typed the string in
it's time to change it over to Morse code. In order to do this we have to take one
character at a time. We also have to find out the pitch and the words per minute. The
word "PAIRS" is example which we use to figure out five words per minute. Each element is equal
dot, and a dash is three dots. So by using the formula we come up with a rounded average
for words per min. The user sets the
the words per minute.
freq = TrackBar1.Value
dit = 60000 / (NumericUpDown1.Value * 50)
dah = dit * 3
Let's take a look at handling the string from the textbox. What I did was run
it through a
For Next Loop so I could check one character at a time.
OK, here comes an interesting part. In the formula we came up with, a timing element in thousandths of a second. There is a total of 50 elements or dots in the word "pairs". So we multiply the value set by the user and then divide. Let's say one of the characters
was C; in Morse code that would be: dash dot dash dot. In
between the dots and dashes
is a time element. That's where we want to have the program stop and do nothing.
We need to hear the difference between the dots and dashes. So how do we do that?
Here's the answer.
ElseIf key = "C" Then
Thread.Sleep(dit * 3)
So we tell the thread to go to sleep. How long the length of the dot
Dit is as you see above.
As you can see from the code above, a character can have up to ten lines of code or more. I am doing this in VB.NET so
speed is not on my side. That's where we break out with
BackGroundWorker. This is where we pick at the string from
Textbox1. Without using the
BackgroundWorker The program would come to a stop.
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object,
ByVal e As System.ComponentModel.DoWorkEventArgs) Handles
len = Microsoft.VisualBasic.Len(batch)
For A = 1 To len
key = Microsoft.VisualBasic.Mid(batch, A, 1)
qso = qso + key
If key = " " Then
Thread.Sleep(dit * 7)
In the demo you have two textboxes. In the first one, type your text
and then set your pitch and words per minute. If anyone would like the full blown
out program drop me an e-mail and I will gladly send it to you with full code to
play with. This was a fun project and that's the kind we like.
I am presently working on a keyer to work of off the sound card DB9 or USB Ports.
Maybe all three.
You might say that I am a throw back from the old days. I started out with the Vic 20. THE WHAT!! Ya that’s right the Vic 20 and the C64 the Timex Plus 64 and so on. So to be able to work with vb basic 2005 express. Is like a kid in a candy shop. When it stops being fun and more like work I hope I have a paycheck. Don't look for any wallpaper here. Just the school of hard knocks