Created
October 14, 2015 20:15
-
-
Save sampowers/ef0b360f6fc2c47ed645 to your computer and use it in GitHub Desktop.
fun with leds
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/sh | |
function rand { foo=$1; echo $((RANDOM%foo+1)); } | |
clearled () { | |
echo 'clear' | |
echo "CLEAR" | nc -w0 -u lights.climagic.com 45444 | |
} | |
function setled { | |
#BINVAL=$(echo "obase=2;$1" | bc) | |
#BINVAL=$(python -c "print ''.join([bin(int(i, 16))[2:].zfill(6) for i in '$1'])") | |
BINVAL=$(python -c "print '{0:09b}'.format($1)") | |
LEDVALS=$(python -c "bin='$BINVAL'; print ''.join([str(ind+1) for ind, x in enumerate(bin) if bin[ind] == '1']) ") | |
clearled | |
echo "$BINVAL, $1, $LEDVALS" | |
echo $LEDVALS | nc -w0 -u lights.climagic.com 45444 && echo "set $LEDVALS" | |
sleep 0.25 | |
} | |
function ranger { | |
mult=$3 ; if [ -z $mult ]; then mult=2; fi | |
if [ $1 -gt $2 ]; then | |
by=$((-1*mult)) | |
else | |
by=$((1*mult)) | |
fi | |
for i in `seq $1 $by $2`; do | |
setled $i | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment