#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
echo "Trying to restart with sudo"
sudo $0 $@
exit
fi
pin=23
#Enable GPIO23
echo $pin > /sys/class/gpio/export
#Set GPIO23 as input
echo in > /sys/class/gpio/gpio$pin/direction
clear
b=0
echo "Not Pressed"
while [ 1 ];
do
v="$(cat /sys/class/gpio/gpio$pin/value)"
if [ "$b" -ne "$v" ]
then
clear
b=$v
if [ "$b" -eq "0" ]
then
echo "Not Pressed"
else
echo "Pressed"
fi
fi
done