Skip to content

Instantly share code, notes, and snippets.

@Everlanders
Created March 6, 2018 15:16
Show Gist options
  • Save Everlanders/f3dc236b9d670b105232952592e5e23a to your computer and use it in GitHub Desktop.
Save Everlanders/f3dc236b9d670b105232952592e5e23a to your computer and use it in GitHub Desktop.
Script to Change the Backlight brightness on the Official Raspberry Pi 7" display.
#!/bin/bash
level=$1
#echo "level given is $level"
if [ $# != 1 ]; then
echo "USAGE: $0 brightness_level (0 to 255)"
exit 1
fi
if [[ $level -ge 0 && $level -le 255 ]]; then
#echo "level given is $level"
echo $level > /sys/class/backlight/rpi_backlight/brightness
echo "Screen brightness set to $level."
exit 0
else
echo "Brightness level $level is out of range! (0 to 255 only)"
exit 1
fi
@sh4un
Copy link

sh4un commented Jun 2, 2018

line 13 gave me a permission denied
i did a little digging and elevated permissions by changing from this:

echo $level > /sys/class/backlight/rpi_backlight/brightness

to this:

sudo sh -c "echo $level > /sys/class/backlight/rpi_backlight/brightness"

Thank you for all your hardwork and research that went into this project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment