Skip to content

Instantly share code, notes, and snippets.

@sstativa
Created November 14, 2017 01:21
Show Gist options
  • Save sstativa/5594fb7b7e56b8f3cceb53ad6beba942 to your computer and use it in GitHub Desktop.
Save sstativa/5594fb7b7e56b8f3cceb53ad6beba942 to your computer and use it in GitHub Desktop.
Bash Morse code Generator
#!/bin/bash
#script: Morse
#Written by Ole-Jørgen Næss Kolsrud
#Thanks to crunchbangers damo, ehde and aibo!
#Also, thank you, Internet=P
#Dependencies: bash, beep
#https://crunchbang.org/forums/viewtopic.php?pid=358511
echo " "
echo -e '\E[1;32m'"\033[1mMORSE CONVERTER\033[0m"
echo " "
echo "Usage: One word at a time, letters must be separated by a space"
echo " "
read -p "Pause between letter parts [ms]: " letter_part_pause
read -p "Pause beetween letters [s]: " letter_pause
#Ett eller annet sted legger vi inn valget om man vil ha tilfeldige bokstaver, eller om man vil taste dem inn sjæl.
a=(1 100 1 300 0 0 0 0 ".-")
b=(1 300 3 100 0 0 0 0 "-...")
c=(1 300 1 100 1 300 1 100 "-.-.")
d=(1 300 2 100 0 0 0 0 "-..")
e=(1 100 0 0 0 0 0 0 ".")
f=(2 100 1 300 1 100 0 0 "..-.")
g=(2 300 1 100 0 0 0 0 "--.")
h=(4 100 0 0 0 0 0 0 "....")
i=(2 100 0 0 0 0 0 0 "..")
j=(1 100 3 300 0 0 0 0 ".---")
k=(1 100 1 300 1 100 0 0 ".-.")
l=(1 100 1 300 2 100 0 0 ".-..")
m=(2 300 0 0 0 0 0 0 "--")
n=(1 300 1 100 0 0 0 0 "-.")
o=(3 300 0 0 0 0 0 0 "---")
p=(1 100 2 300 1 100 0 0 ".--.")
q=(2 300 1 100 1 300 0 0 "--.-")
r=(1 100 1 300 1 100 0 0 ".-.")
s=(3 100 0 0 0 0 0 0 "...")
t=(1 300 0 0 0 0 0 0 "-")
u=(2 100 1 300 0 0 0 0 "..-")
v=(3 100 1 300 0 0 0 0 "...-")
w=(1 100 2 300 0 0 0 0 ".--")
x=(1 300 2 100 1 300 0 0 "-..-")
y=(1 300 1 100 2 300 0 0 "-.--")
z=(2 300 2 100 0 0 0 0 "--..")
n1=(1 100 4 300 0 0 0 0 ".----")
n2=(2 100 3 300 0 0 0 0 "..---")
n3=(3 100 2 300 0 0 0 0 "...--")
n4=(4 100 1 300 0 0 0 0 "....-")
n5=(5 100 0 0 0 0 0 0 ".....")
n6=(1 300 4 100 0 0 0 0 "-....")
n7=(2 300 3 100 0 0 0 0 "--...")
n8=(3 300 2 100 0 0 0 0 "---..")
n9=(4 300 1 100 0 0 0 0 "----.")
n0=(5 300 0 0 0 0 0 0 "-----")
space=""
while true
do
read -p "Text to convert: " tekst_inn
tekst_inn_ARRAY=(`echo $tekst_inn | tr " " "\n"`) #Hva er tr? Hvorfor \n?
an=0
for ax in "${tekst_inn_ARRAY[@]}"
do
bokstav[an]=$ax
an=$an+1
done
bokstav_count=${#bokstav[@]}
am=0
while [ $am -le $bokstav_count ] ; do
for as in ${bokstav[am]} #Hvordan kunne jeg ha ordna det sånn at $as kunne vært et helt array?
do
eval 'morse0="${'"$as[0]"'}"' #Jeg må lære hvorfor dette funker...
eval 'morse1="${'"$as[1]"'}"'
eval 'morse2="${'"$as[2]"'}"'
eval 'morse3="${'"$as[3]"'}"'
eval 'morse4="${'"$as[4]"'}"'
eval 'morse5="${'"$as[5]"'}"'
eval 'morse6="${'"$as[6]"'}"'
eval 'morse7="${'"$as[7]"'}"'
eval 'morse8="${'"$as[8]"'}"'
echo "${bokstav[am]} $morse8"
beep -r $morse0 -D $letter_part_pause -f 600 -l $morse1 2 > /dev/null #Kjører første gruppe
beep -r $morse2 -D $letter_part_pause -f 600 -l $morse3 2 > /dev/null #Kjører andre gruppe
beep -r $morse4 -D $letter_part_pause -f 600 -l $morse5 2 > /dev/null #Kjører tredje gruppe
beep -r $morse6 -D $letter_part_pause -f 600 -l $morse7 2 > /dev/null #Kjører fjerde gruppe
sleep $letter_pause
done
((am=am+1))
done
unset bokstav[@]
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment