Hardware Reference
In-Depth Information
function close() { # pin
echo $1 >$SYS/unexport
}
function put() { # pin value
echo $2 >$SYS/gpio$1/value
}
function get() { # pin
read BIT <$SYS/gpio$1/value
echo $BIT
}
count=0
SYS=/sys/class/gpio
open $INP in
open $OUT out
put $OUT 1
LBIT=2
while true ; do
RBIT=$(get $INP)
if [ $RBIT −ne $LBIT ] ; then
put $OUT $RBIT
printf "%04d Status : %d\n" $count $RBIT
LBIT=$RBIT
let count=count+1
else
sleep 1
fi
done
# End
The following is an example session:
# ./input
0000 Status : 0
0001 Status : 1
0002 Status : 0
0003 Status : 1
^C
#
When GPIO 25 is grounded, 0 should be read, as reported in line 0000 of the
example. If you then apply a high (for example, from the +3.3 V supply), a 1 should be
reported.
 
Search WWH ::




Custom Search