Simplest way to add an on-off button July 21, 2017 10:42AM |
Registered: 7 years ago Posts: 16 |
sudo rm /etc/resolv.conf sudo sh -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf '
sudo pacman -S wiringpi
sudo nano /home/alarm/buttononoff
#!/bin/bash pin=9 gpio mode $pin in gpio mode $pin up while true; do var=$(gpio read $pin) if [ "$var" -eq "0" ] ; then echo shutdown sudo shutdown -h now fi sleep 0.1 done
sudo chmod +x buttononoff
sudo nano /lib/systemd/system/button.service
[Unit] Description=Button Service After=multi-user.target [Service] Type=idle ExecStart=/home/alarm/buttononoff StandardOutput=null [Install] WantedBy=multi-user.target Alias=button.service
sudo chmod 644 /lib/systemd/system/button.service sudo systemctl daemon-reload sudo systemctl enable button.service
Re: Simplest way to add an on-off button July 25, 2017 03:34PM |
Admin Registered: 13 years ago Posts: 4,680 |
Re: Simplest way to add an on-off button July 31, 2017 09:16AM |
Registered: 7 years ago Posts: 16 |
Re: Simplest way to add an on-off button October 12, 2017 02:15AM |
#!/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
Re: Simplest way to add an on-off button October 12, 2017 02:31AM |
Registered: 6 years ago Posts: 1 |
#!/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
Re: Simplest way to add an on-off button October 23, 2017 02:04PM |
Registered: 6 years ago Posts: 4 |
Re: Simplest way to add an on-off button November 11, 2018 05:39PM |
Registered: 5 years ago Posts: 2 |