Skip to content

Instantly share code, notes, and snippets.

@kostasdizas
Last active September 7, 2015 13:59
Show Gist options
  • Save kostasdizas/8d1f98338e6c25c2cf23 to your computer and use it in GitHub Desktop.
Save kostasdizas/8d1f98338e6c25c2cf23 to your computer and use it in GitHub Desktop.
Control the LEDs on a Raspberry Pi
#! /bin/bash
# led_control [on|off] : Turn the LEDs on or off
function display_usage() {
echo "Control the Raspberry Pi leds"
echo -e "\nUsage:\n$0 [on|off]\n"
exit 1
}
[ $# -eq 0 ] && display_usage
[ "$1" = "on" ] && value=255 || { [ "$1" = "off" ] && value=0 || display_usage; }
printf "Turning leds %s\n" $(awk '{print toupper($0)}' <<< $1)
for led in /sys/class/leds/led*; do
echo $value | sudo tee -a ${led}/brightness > /dev/null
done
unset led
unset value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment