Using the controls in a program
Now that we know how to disconnect the LEDs from the system control and turn them on, let's put it together in a program.
Type the following program and name it ledon.sh
:
ledon.sh 1: #!/bin/sh 2: # Replace the names with what is used on your system 3: # Disconnect all 4 LEDs on the BeagleBone so we can use it. 4: echo none > /sys/class/leds/beaglebone:green:usr0/trigger 5: echo none > /sys/class/leds/beaglebone:green:usr1/trigger 6: echo none > /sys/class/leds/beaglebone:green:usr2/trigger 7: echo none > /sys/class/leds/beaglebone:green:usr3/trigger 8: # Turn on all 4 LEDs 9: echo 255 > /sys/class/leds/beaglebone:green:usr0/brightness 10: echo 255 > /sys/class/leds/beaglebone:green:usr1/brightness 11: echo 255 > /sys/class/leds/beaglebone:green:usr2/brightness 12: echo 255 > /sys/class/leds/beaglebone:green:usr3/brightness
Let's analyze the preceding program:
- The first line tells the Linux kernel that this is a shell script...