53 lines
1.4 KiB
Plaintext
53 lines
1.4 KiB
Plaintext
'Requires component 'gb.sdl2.audio'
|
|
|
|
Public Sub Main()
|
|
Dim sMessage As String = "Hello World"
|
|
Dim sFile As String = File.Load("../morse.txt") 'Contains A,.- B,-... etc
|
|
Dim sChar As New String[]
|
|
Dim sMorse As New String[]
|
|
Dim sOutPut As New String[]
|
|
Dim sTemp As String
|
|
Dim siCount, siLoop As Short
|
|
Dim bTrigger As Boolean
|
|
Dim fDelay As Float = 0.4
|
|
|
|
If Not Exist("/tmp/dot.ogg") Then Copy "../dot.ogg" To "/tmp/dot.ogg" 'Sounds downloaded from
|
|
If Not Exist("/tmp/dash.ogg") Then Copy "../dash.ogg" To "/tmp/dash.ogg" 'https://en.wikipedia.org/wiki/Morse_code#Letters.2C_numbers.2C_punctuation.2C_prosigns_for_Morse_code_and_non-English_variants
|
|
|
|
For Each sTemp In Split(sFile, gb.NewLine)
|
|
sChar.add(Split(Trim(sTemp))[0])
|
|
sMorse.add(Split(Trim(sTemp))[1])
|
|
Next
|
|
|
|
For siCount = 1 To Len(sMessage)
|
|
For siLoop = 0 To sChar.Max
|
|
If sChar[siLoop] = Mid(UCase(sMessage), siCount, 1) Then
|
|
sOutPut.Add(sMorse[siLoop])
|
|
bTrigger = True
|
|
Break
|
|
End If
|
|
Next
|
|
If bTrigger = False Then sOutPut.Add(" ")
|
|
bTrigger = False
|
|
Next
|
|
|
|
Print sOutPut.Join(" ")
|
|
|
|
For siCount = 0 To Len(sMessage) - 1
|
|
For siLoop = 0 To Len(sOutPut[siCount]) - 1
|
|
If Mid(sOutPut[siCount], siLoop + 1, 1) = "." Then
|
|
Music.Load("/tmp/dot.ogg")
|
|
Music.Play
|
|
Wait fDelay
|
|
Else If Mid(sOutPut[siCount], siLoop + 1, 1) = "-" Then
|
|
Music.Load("/tmp/dash.ogg")
|
|
Music.Play
|
|
Wait fDelay
|
|
Else
|
|
Wait fDelay
|
|
Endif
|
|
Next
|
|
Next
|
|
|
|
End
|