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

#!/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 ""
  ((counter = counter + 1))
   if [ "$counter" -gt "10" ] ; then
      echo Shutting Down..
      sudo shutdown -h now
   fi
      if [ "$counter" -gt "3" ] && [ "$counter" -lt "10" ]; then
        echo Rebooting..
        sudo shutdown -r now
      fi
 fi
sleep 0.1
done


Hi , i'm sure there is neater ways than this.. but here's my attempt at making the the On-Off Button dual action.. Press for ~3 sec's and we reboot... ~10 secs and it powers off.

Also , I added LED status using this method..
https://howchoo.com/g/ytzjyzy4m2e/build-a-simple-raspberry-pi-led-power-status-indicator

Viewing all articles
Browse latest Browse all 1863

Trending Articles