Last active
September 7, 2015 13:59
-
-
Save kostasdizas/8d1f98338e6c25c2cf23 to your computer and use it in GitHub Desktop.
Control the LEDs on a Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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