Quantcast
Channel: PirateBox Forum - Raspberry Pi(rate)Box
Viewing all articles
Browse latest Browse all 1863

Re: Simplest way to add an on-off button

$
0
0
Oops:

Yeah , ok.. Flawed logic.. my first script still needed some work as it still thought a 10 second push was a reboot request , due to Reboot test going true @ 3 second's in..

try this...

#!/bin/bash
pin=9
gpio mode $pin in
gpio mode $pin up
counter=0
while true; do
 var=$(gpio read $pin)
 if [ "$var" -eq "0" ] ; then
		echo Button has been pressed..
		echo ""
		sleep 1
		((counter = counter + 1))
		if [ "$counter" -gt "10" ] ; then
		  echo Shutting Down..
		  sudo shutdown -h now
		fi
 else
		if [ "$counter" -gt "3" ] ; then
			echo Rebooting..
			sudo shutdown -r now
		fi
		counter=0
 fi
sleep 0.1
done

Viewing all articles
Browse latest Browse all 1863

Trending Articles