#!/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