Created
September 9, 2025 14:44
-
-
Save DesktopECHO/3d29f622972f23b5537337ff0f2d8d01 to your computer and use it in GitHub Desktop.
kittload - Sequentially flash the user LEDs on a BeagleBone Black, flash speed based is based on system load
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
| #!/bin/bash | |
| # BeagleBone "Knight Rider" LED chase with edge pause | |
| # SPEED_BASE is the fastest pace, PAUSE is edge off-time | |
| SPEED_BASE=${SPEED_BASE:-0.05} | |
| PAUSE=${PAUSE:-0.02} | |
| LEDS=( | |
| /sys/class/leds/beaglebone:green:usr0/brightness | |
| /sys/class/leds/beaglebone:green:usr1/brightness | |
| /sys/class/leds/beaglebone:green:usr2/brightness | |
| /sys/class/leds/beaglebone:green:usr3/brightness | |
| ) | |
| # Disable kernel triggers and clear | |
| for led in "${LEDS[@]}"; do | |
| trig_file="${led%/*}/trigger" | |
| echo none > "$trig_file" 2>/dev/null || sudo sh -c "echo none > $trig_file" | |
| echo 0 > "$led" 2>/dev/null || sudo sh -c "echo 0 > $led" | |
| done | |
| led_on() { | |
| idx=$1 | |
| if [ $idx -ge 0 ] && [ $idx -lt ${#LEDS[@]} ]; then | |
| echo 1 > "${LEDS[$idx]}" 2>/dev/null || sudo sh -c "echo 1 > ${LEDS[$idx]}" | |
| fi | |
| } | |
| led_off_all() { | |
| for i in "${!LEDS[@]}"; do | |
| echo 0 > "${LEDS[$i]}" 2>/dev/null || sudo sh -c "echo 0 > ${LEDS[$i]}" | |
| done | |
| } | |
| # Position runs back and forth | |
| POS=(0 1 2 3 2 1) | |
| # Calculate speed factor based on system load (loadavg 1min) | |
| get_speed() { | |
| load=$(awk '{print $1}' /proc/loadavg) | |
| # scale speed: base * (1 + load) | |
| awk -v base="$SPEED_BASE" -v l="$load" 'BEGIN { printf "%.3f", base * (1 + l) }' | |
| } | |
| while true; do | |
| SPEED=$(get_speed) | |
| for p in "${POS[@]}"; do | |
| led_off_all | |
| led_on $p | |
| sleep $SPEED | |
| # If we’re at either edge, add a pause with everything off | |
| if [ $p -eq 0 ] || [ $p -eq 3 ]; then | |
| led_off_all | |
| sleep $PAUSE | |
| fi | |
| done | |
| done | |
| ## chmod +x /usr/local/bin/kittload | |
| ## sudo crontab -e ## Edit crontab and add this line to start at boot: | |
| ## @reboot /bin/bash /usr/local/bin/kittload >/dev/null 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment