Skip to content

Instantly share code, notes, and snippets.

@katspaugh
Last active August 29, 2015 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katspaugh/7cce38ff321b30df882e to your computer and use it in GitHub Desktop.
Save katspaugh/7cce38ff321b30df882e to your computer and use it in GitHub Desktop.
Raspberry Pi car-controlling bash script
#!/bin/bash
cd /sys/class/gpio
function left {
echo 4 > export
echo out > gpio4/direction
echo $1 > gpio4/value
echo 4 > unexport
}
function right {
echo 7 > export
echo out > gpio7/direction
echo $1 > gpio7/value
echo 7 > unexport
}
function forward {
left 1 && right 1
}
function stop {
left 0 && right 0
}
function turn_left {
right 0 && left 1
}
function turn_right {
right 1 && left 0
}
while true; do
read -t0.1 -n1 KEY
case "$KEY" in
"w")
forward
;;
"a")
turn_left
;;
"d")
turn_right
;;
"s")
stop
;;
esac
done
stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment