Created
December 9, 2021 19:22
-
-
Save zyphlar/fddcd7af0018e0f3ded440a9f782a009 to your computer and use it in GitHub Desktop.
cylon/loop led scanner flasher routine in bash
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
led0path=/sys/class/leds/$SOME_LED_HERE/brightness | |
led1path=/sys/class/leds/$SOME_LED_HERE/brightness | |
led2path=/sys/class/leds/$SOME_LED_HERE/brightness | |
run=1 | |
led=0 | |
up=1 | |
minled=0 | |
maxled=2 | |
onoff=0 | |
trap doexit SIGINT | |
doexit() { | |
run=0 | |
# reset all leds to end | |
onoff=1 | |
led=0 | |
setled | |
led=1 | |
setled | |
led=1 | |
setled | |
} | |
setled() { | |
if [ $led -eq 0 ]; | |
then | |
echo $onoff > $led0path | |
fi | |
if [ $led -eq 1 ]; | |
then | |
echo $onoff > $led1path | |
fi | |
if [ $led -eq 2 ]; | |
then | |
echo $onoff > $led2path | |
fi | |
} | |
run_cylon() { | |
while [ $run -eq 1 ]; | |
do | |
onoff=0 | |
setled | |
if [ $up -eq 0 ]; | |
then | |
led=$((led - 1)) | |
elif [ $up -eq 1 ]; | |
then | |
led=$((led + 1)) | |
fi | |
if [ $led -ge $maxled ]; | |
then | |
up=0 | |
fi | |
if [ $led -le $minled ]; | |
then | |
up=1 | |
fi | |
onoff=255 | |
setled | |
sleep 1 | |
done | |
} | |
run_loopy() { | |
while [ $run -eq 1 ]; | |
do | |
onoff=0 | |
setled | |
if [ $up -eq 0 ]; | |
then | |
led=$((led - 1)) | |
elif [ $up -eq 1 ]; | |
then | |
led=$((led + 1)) | |
fi | |
if [ $led -gt $maxled ]; | |
then | |
led=$minled | |
fi | |
if [ $led -lt $minled ]; | |
then | |
led=$maxled | |
fi | |
onoff=255 | |
setled | |
sleep 1 | |
done | |
} | |
# clear all leds to start | |
onoff=0 | |
led=0 | |
setled | |
led=1 | |
setled | |
led=1 | |
setled | |
#up=0 | |
#run_loopy | |
run_cylon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment