Created
April 20, 2015 02:43
-
-
Save jkunkee/10ca0ce8b78d8b0e8cf8 to your computer and use it in GitHub Desktop.
Raspberry Pi 2 Gray Code Light Blinker
This file contains 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 | |
BASE=/sys/class/gpio | |
RED=20 | |
YELLOW=16 | |
GREEN=12 | |
function on() { | |
echo 1 > $BASE/gpio$1/value | |
} | |
function off() { | |
echo 0 > $BASE/gpio$1/value | |
} | |
function init() { | |
echo Remuxing... | |
echo $RED > $BASE/export | |
echo $YELLOW > $BASE/export | |
echo $GREEN > $BASE/export | |
sleep 1 | |
echo Setting directions... | |
echo out > $BASE/gpio$RED/direction | |
echo out > $BASE/gpio$YELLOW/direction | |
echo out > $BASE/gpio$GREEN/direction | |
sleep 1 | |
echo Initializing values... | |
off $RED | |
off $YELLOW | |
off $GREEN | |
} | |
init | |
function randdelay() { | |
local integer=$[ $RANDOM % 2 ] | |
local mantissa= | |
if [ "$integer" == "1" ]; then | |
mantissa=$[ $RANDOM % 50 ] | |
else | |
mantissa=$[ ( $RANDOM % 50 ) + 50 ] | |
fi | |
sleep ${integer}.${mantissa}s | |
} | |
echo Blinking\! | |
while true | |
do | |
#000 | |
on $RED | |
randdelay | |
#001 | |
on $YELLOW | |
randdelay | |
#011 | |
off $RED | |
randdelay | |
#010 | |
on $GREEN | |
randdelay | |
#110 | |
on $RED | |
randdelay | |
#111 | |
off $YELLOW | |
randdelay | |
#101 | |
off $RED | |
randdelay | |
#100 | |
off $GREEN | |
randdelay | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment