/
bashLED
executable file
·40 lines (37 loc) · 1.09 KB
/
bashLED
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# A small Bash script to set up User LED3 to be turned on or off from
# Linux console. Written by Derek Molloy (derekmolloy.ie) for the
# book Exploring BeagleBone.
LED3_PATH=/sys/class/leds/beaglebone:green:usr3
# Example bash function
function removeTrigger
{
echo "none" >> "$LED3_PATH/trigger"
}
echo "Starting the LED Bash Script"
if [ $# -eq 0 ]; then
echo "There are no arguments. Usage is:"
echo -e " bashLED Command \n where command is one of "
echo -e " on, off, flash or status \n e.g. bashLED on "
exit 2
fi
echo "The LED Command that was passed is: $1"
if [ "$1" == "on" ]; then
echo "Turning the LED on"
removeTrigger
echo "1" >> "$LED3_PATH/brightness"
elif [ "$1" == "off" ]; then
echo "Turning the LED off"
removeTrigger
echo "0" >> "$LED3_PATH/brightness"
elif [ "$1" == "flash" ]; then
echo "Flashing the LED"
removeTrigger
echo "timer" >> "$LED3_PATH/trigger"
sleep 1
echo "100" >> "$LED3_PATH/delay_off"
echo "100" >> "$LED3_PATH/delay_on"
elif [ "$1" == "status" ]; then
cat "$LED3_PATH/trigger";
fi
echo "End of the LED Bash Script"