You may not understand what I do… but it is still awesome.

How to control the onboard ACT LED in bash

This post will show you how to control the onboard ACT led on the raspberry pi. To start with, run the following command to allow you to use the led:

sudo echo none > /sys/class/leds/led0/trigger

The above will prevent the light from acting as a disk activity indicator (the default.

You may need to run the folllowing command if it says access denied (even with sudo):

sudo chmod -r 777 /sys/class/leds/led0

This will ensure that you have access to it.

To turn the led on, use this:

sudo echo 1 > /sys/class/leds/led0/brightness

To turn the led off, use this:

sudo echo 0 > /sys/class/leds/led0/brightness

To return the led back to it’s original state, either restart the raspberry pi, or run this command:

sudo echo mmc0 > /sys/class/leds/led0/trigger

Here are some utility functions:

# Turns the led on.
# usage: on
# e.g. on will turn the led on.
on() {
sudo echo 1 > /sys/class/leds/led0/brightness
}
# Turns the led off.
# usage: off
# e.g. off will turn the led off.
off() {
sudo echo 0 > /sys/class/leds/led0/brightness
}
# a 0.6s gap.
# usage: gap
# e.g. gap will give a 0.6s gap.
gap() {
sleep 0.6
}

# a pulse.
# usage: pulse 
# e.g. pulse 0.5 gives a 0.5 pulse with a 0.6 second gap at the end.
pulse() {
echo -ne "|$1| "
on
sleep $1
off
gap
}

# a quick pulse.
# usage: quickpulse 
# e.g. pulse 0.5 gives a 0.5 pulse with a 0.2 second gap at the end.
quickpulse() {
echo -ne "[$1] "
on
sleep $1
off
sleep 0.2
}

#a new line character in the console
newline() {
echo ""
}
#a dividing line
divider() {
newline
gap
echo "-----"
gap
newline
}

, , ,

Leave a Reply