Last active
March 4, 2023 17:54
-
-
Save themactep/24adfe43d3d29f20eacb75294d9d4035 to your computer and use it in GitHub Desktop.
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 | |
# GPIO switcher | |
# Paul Philippov <[email protected]> | |
PIN=$1 | |
MODE=$2 | |
if [ -z "$PIN" ] || [ -z "$MODE" ]; then | |
echo "Usage: $0 <pin#> <1|0|x>" | |
exit 1 | |
fi | |
if [ "x" = "$MODE" ]; then | |
if [ ! -d "/sys/class/gpio/gpio${PIN}" ]; then | |
echo "Pin ${PIN} is not exported." | |
exit 2 | |
fi | |
echo $PIN > /sys/class/gpio/unexport | |
else | |
if [ ! -d "/sys/class/gpio/gpio${PIN}" ]; then | |
echo $PIN > /sys/class/gpio/export | |
echo out > /sys/class/gpio/gpio${PIN}/direction | |
fi | |
echo $MODE > /sys/class/gpio/gpio${PIN}/value | |
fi | |
dmesg | tail -10 | |
ls -l /sys/class/gpio/ | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment