How to loop on gpio?
-
13-12-2019 - |
Question
How can gpio be used to control execution? The following works for showing the input value of gpio63
echo 63 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio63/direction
cat /sys/class/gpio/gpio63/value
But I've tried a number of things like
while [ /sys/class/gpio/gpio63/value = "1" ]
do
sleep 1
done
without success.
Solution
You're comparing the string "/sys/class/gpio/gpio63/value" to the string "1". They'll never be equal. If you're looking for a "1" as the content of the file named "/sys/class/gpio/gpio63/value" you should say
while [ "$(cat /sys/class/gpio/gpio64/value)" = 1 ]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow