Skip to content

Instantly share code, notes, and snippets.

@cwoodall
Created June 9, 2012 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwoodall/2902908 to your computer and use it in GitHub Desktop.
Save cwoodall/2902908 to your computer and use it in GitHub Desktop.
Toggle LED with a switch
#!/bin/sh
echo "25" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio25/direction
echo "24" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio24/direction
OUTPUT="0"
INPUT="$(cat /sys/class/gpio/gpio24/value)"
while [ 1 ]; do
if [ "$INPUT" -eq "1" ]; then
echo "$OUTPUT" > /sys/class/gpio/gpio25/value
if [ "$OUTPUT" -eq "0" ]; then
let OUTPUT="1"
else
let OUTPUT="0"
fi
sleep .5
else
echo "0" > /sys/class/gpio/gpio25/value
fi
let INPUT="$(cat /sys/class/gpio/gpio24/value)"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment