Last active
January 19, 2020 17:58
-
-
Save pettazz/3759bbc9135f42b103e9bc31a2f4addb to your computer and use it in GitHub Desktop.
Set the brightness on certain Raspberry Pi compatible screens as a percentage
This file contains hidden or 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
#!/usr/bin/env bash | |
if ! [[ $1 =~ ^-?[0-9]+$ ]]; then | |
echo "Percentage must be an integer" 1>&2 | |
exit 1 | |
fi | |
if (( $1 < 0 || $1 > 100 )); then | |
echo "Percentage value must be at least 0 or at most 100" 1>&2 | |
exit 1 | |
fi | |
curr=`cat /sys/class/backlight/rpi_backlight/brightness` | |
target=`printf %.0f $(echo "$1 * 0.01 * 255" | bc)` | |
(( $curr > $target )) && inc=-1 || inc=1 | |
read -d "" looper << LOOPERDEF || true | |
for i in \$(seq $curr $inc $target); | |
do | |
echo \$i | tee /sys/class/backlight/rpi_backlight/brightness > /dev/null; | |
done | |
LOOPERDEF | |
sudo bash -c "$(echo $looper)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment