Added write-morse-code.ps1

This commit is contained in:
Markus Fleschutz 2020-12-21 17:03:36 +00:00
parent e2887fa9cd
commit cc399370af
2 changed files with 82 additions and 0 deletions

View File

@ -62,6 +62,7 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol
* [write-big.ps1](Scripts/write-big.ps1) - writes the given text in big letters
* [write-blue.ps1](Scripts/write-blue.ps1) - writes the given text in a blue foreground color
* [write-green.ps1](Scripts/write-green.ps1) - writes the given text in a green foreground color
* [write-morse-code.ps1](Scripts/write-morse-code.ps1) - writes the given text in Morse code
* [write-MOTD.ps1](Scripts/write-MOTD.ps1) - writes the message of the day (MOTD)
* [write-red.ps1](Scripts/write-red.ps1) - writes the given text in a red foreground color
* [write-typewriter.ps1](Scripts/write-typewriter.ps1) - writes the given text with the typewriter effect

81
Scripts/write-morse-code.ps1 Executable file
View File

@ -0,0 +1,81 @@
#!/snap/bin/powershell
# Syntax: ./write-morse-code.ps1 [<text>]
# Description: writes the given text in Morse code
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
param([String]$Text)
function dot() {
write-host "." -nonewline
start-sleep -milliseconds 100
}
function dash() {
write-host "-" -nonewline
start-sleep -milliseconds 300
}
function pause() {
write-host " " -nonewline
start-sleep -milliseconds 400
}
function Char2MorseCode() { param([String]$Char)
switch($Char) {
'A' { dot; dash }
'B' { dash; dot; dot; dot }
'C' { dash; dot; dash; dot }
'D' { dash; dot; dot }
'E' { dot }
'F' { dot; dot; dash; dot }
'G' { dash; dash; dot }
'H' { dot; dot; dot; dot }
'I' { dot; dot }
'J' { dot; dash; dash; dash }
'K' { dash; dot; dash }
'L' { dot; dash; dot; dot }
'M' { dash; dash }
'N' { dash; dot }
'O' { dash; dash; dash }
'P' { dot; dash; dash; dot }
'Q' { dash; dash; dot; dash }
'R' { dot; dash; dot }
'S' { dot; dot; dot }
'T' { dash }
'U' { dot; dot; dash }
'V' { dot; dot; dot; dash }
'W' { dot; dash; dash }
'X' { dash; dot; dot; dash }
'Y' { dash; dot; dash; dash }
'Z' { dash; dash; dot; dot }
'1' { dot; dash; dash; dash; dash }
'2' { dot; dot; dash; dash; dash }
'3' { dot; dot; dot; dash; dash }
'4' { dot; dot; dot; dot; dash }
'5' { dot; dot; dot; dot; dot }
'6' { dash; dot; dot; dot; dot }
'7' { dash; dash; dot; dot; dot }
'8' { dash; dash; dash; dot; dot }
'9' { dash; dash; dash; dash; dot }
'0' { dash; dash; dash; dash; dash }
default { pause }
}
}
try {
if ($Text -eq "" ) {
[String]$Text = read-host "Enter text to write"
}
[char[]]$ArrayOfChars = $Text.ToUpper()
foreach($Char in $ArrayOfChars) {
Char2MorseCode $Char
}
write-host ""
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}