Morse code program in basic

Started by VK5KKS, Aug 09, 2024, 02:42 PM

Previous topic - Next topic

VK5KKS

I wrote the following code way back when I first got into programming using Quick Basic 4.5. I have discovered that QB45 is now available as QB64 and will run on Windows, Linux and Mac. So, if you're interested you might like to have a play, use the code here to get some morse practice going. After programming in c++ for twenty years for DoD, basic is kinda nice to play about with.  :)


' morse07.bas
' kevin thomas, 1989, 1991, 2024
' send a random character and let the user
' input their response.

Randomize Timer
Option Base 1
Const tone = 750
Const max = 37
Color 7

start:
char$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890."
sent$ = ""
user_responses$ = ""
count = 1
wrong = 0
right = 0

Input "How many characters shall I send "; num
Print

Do
    x = Int(Rnd * max) + 1
    sound_char (x)
    Input "What was that character "; response$
    If UCase$(response$) = Mid$(char$, x, 1) Then
        Color 2: Print "Correct!": Color 7
        right = right + 1
    Else
        Color 3: Print "Wrong!": Color 7
        Sound 200, 5
        Sound 30000, 20
        wrong = wrong + 1
    End If
    sent$ = sent$ + Mid$(char$, x, 1) + " "
    user_responses$ = user_responses$ + UCase$(response$) + " "
    count = count + 1
Loop While count <= num And response$ <> "end"
Cls

Print
Print " sent      "; sent$;
Print
Print " responses "; user_responses$;
Print: Print
Print " right = "; right
Print " wrong = "; wrong
Print right / num * 100

Input "Again "; again$
If again$ = "Y" Or again$ = "y" Then
    Print
    GoTo start:
End If

End ' of program!

Sub sound_char (n)
    Select Case n
        Case 1: dit: dah
        Case 2: dah: dit: dit: dit
        Case 3: dah: dit: dah: dit
        Case 4: dah: dit: dit
        Case 5: dit
        Case 6: dit: dit: dah: dit
        Case 7: dah: dah: dit
        Case 8: dit: dit: dit: dit
        Case 9: dit: dit
        Case 10: dit: dah: dah: dah
        Case 11: dah: dit: dah
        Case 12: dit: dah: dit: dit
        Case 13: dah: dah
        Case 14: dah: dit
        Case 15: dah: dah: dah
        Case 16: dit: dah: dah: dit
        Case 17: dah: dah: dit: dah
        Case 18: dit: dah: dit
        Case 19: dit: dit: dit
        Case 20: dah
        Case 21: dit: dit: dah
        Case 22: dit: dit: dit: dah
        Case 23: dit: dah: dah
        Case 24: dah: dit: dit: dah
        Case 25: dah: dit: dah: dah
        Case 26: dah: dah: dit: dit
        Case 27: dit: dah: dah: dah: dah
        Case 28: dit: dit: dah: dah: dah
        Case 29: dit: dit: dit: dah: dah
        Case 30: dit: dit: dit: dit: dah
        Case 31: dit: dit: dit: dit: dit
        Case 32: dah: dit: dit: dit: dit
        Case 33: dah: dah: dit: dit: dit
        Case 34: dah: dah: dah: dit: dit
        Case 35: dah: dah: dah: dah: dit
        Case 36: dah: dah: dah: dah: dah
        Case 37: dit: dah: dit: dah: dit: dah
    End Select
    char_delay
End Sub

Sub dit
    Sound tone, 1
    Sound 25000, 1
End Sub

Sub dah
    Sound tone, 3
    Sound 25000, 1
End Sub

' the delay between characters (letters and numbers etc)
' can be lenthened to help with learning
Sub char_delay
    Sound 25000, 3 ' should be 3
End Sub

Sub word_delay
    Sound 25000, 7 ' should be 7
End Sub


VK5TOM

Nice little program there Kevin, QB64 accepted the copy paste and it compiled first go!
British Amateur Television Club
ACRMGB
WICEN SA