Skip to content

Instantly share code, notes, and snippets.

@TimRepke
Last active April 11, 2016 14:09
Show Gist options
  • Save TimRepke/00b65c5d349f23008820266b29bb4536 to your computer and use it in GitHub Desktop.
Save TimRepke/00b65c5d349f23008820266b29bb4536 to your computer and use it in GitHub Desktop.
Use your ThinkPad 'i'-LED to morse stuff

ThinkPad morse (aka ThinkBlink)

Usage:

$ sudo ./morse.sh "sos"
s . . . 
o - - - 
s . . .

The dot/slash notation is displayed as your ThinkPad blinks along. You might have to change the led_num variable. Feel free to tweak the timings. They are not accurate all the time... (no pun intended)

Special thanks to Torsten, who helped along the way.

#!/bin/bash
short=0.1
long=0.5
gap=0.5
led_num=0
declare -A morse
morse["a"]=".-"
morse["b"]="-..."
morse["c"]="-.-."
morse["d"]="-.."
morse["e"]="."
morse["f"]="..-."
morse["g"]="--."
morse["h"]="...."
morse["i"]=".."
morse["j"]=".---"
morse["k"]="-.-"
morse["l"]=".-.."
morse["m"]="--"
morse["n"]="-."
morse["o"]="---"
morse["p"]=".--."
morse["q"]="--.-"
morse["r"]=".-."
morse["s"]="..."
morse["t"]="-"
morse["u"]="..-"
morse["v"]="...-"
morse["w"]=".--"
morse["x"]="-..-"
morse["y"]="-.--"
morse["z"]="--.."
function led_on {
echo "${led_num} on" > /proc/acpi/ibm/led
}
function led_off {
echo "${led_num} off" > /proc/acpi/ibm/led
}
function blink_short {
led_on
sleep $short
led_off
sleep $gap
}
function blink_long {
led_on
sleep $long
led_off
sleep $gap
}
function morse_letter {
while read -n1 b; do
echo -n "$b "
case $b in
".") blink_short
;;
"-") blink_long
;;
*) ;;
esac
done < <(echo -n "$1")
}
while read -n1 l; do
echo -n "$l "
if [[ -v morse[$l] ]] ; then
morse_letter ${morse[$l]}
fi
echo ""
sleep $gap
done < <(echo -n "${1,,}")
led_on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment