From 311c16300aecd506c7fed88bf7df97444ee09e52 Mon Sep 17 00:00:00 2001 From: ImpressiveTaste <94606213+ImpressiveTaste@users.noreply.github.com> Date: Sat, 12 Feb 2022 10:06:16 +0100 Subject: [PATCH 1/3] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e31d232..21f1d3a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # pi-power-button -Scripts used in our official [Raspberry Pi power button guide](https://howchoo.com/g/mwnlytk3zmm/how-to-add-a-power-button-to-your-raspberry-pi). +## Details + +This software allows to turn on and off your raspberry. For turning off the raspberry you will need to hold the button for 3seconds. This makes unintentional turn offs or static current not turn off the raspberry randomly. ## Installation -1. [Connect to your Raspberry Pi via SSH](https://howchoo.com/g/mgi3mdnlnjq/how-to-log-in-to-a-raspberry-pi-via-ssh) -1. Clone this repo: `git clone https://github.com/Howchoo/pi-power-button.git` +1. Clone this repo: `git clone https://github.com/ImpressiveTaste/pi-power-button` 1. Optional: Edit line 9/10 in listen-for-shutdown.py to your preferred pin (Please see "Is it possible to use another pin other than Pin 5 (GPIO 3/SCL)?" below!) 1. Run the setup script: `./pi-power-button/script/install` From afdd2c88f7706d2cf452fbbe1b3adca6141483aa Mon Sep 17 00:00:00 2001 From: ImpressiveTaste <94606213+ImpressiveTaste@users.noreply.github.com> Date: Sat, 12 Feb 2022 10:07:32 +0100 Subject: [PATCH 2/3] Update listen-for-shutdown.py --- listen-for-shutdown.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/listen-for-shutdown.py b/listen-for-shutdown.py index cecc42b..76d8476 100755 --- a/listen-for-shutdown.py +++ b/listen-for-shutdown.py @@ -3,10 +3,21 @@ import RPi.GPIO as GPIO import subprocess - +import time GPIO.setmode(GPIO.BCM) GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP) -GPIO.wait_for_edge(3, GPIO.FALLING) + +stay=1 #incidcates if shutdown hasbeen sent correctly + +while stay: + GPIO.wait_for_edge(3, GPIO.FALLING) #button is pressed + for i in range(30): #wait for a second + time.sleep(0.1) + if GPIO.input(3) == 1: #if button not pressed + stay=1 + break + else: + stay=0 subprocess.call(['shutdown', '-h', 'now'], shell=False) From 50935e57a0a3ac3e58b1ef717ac01f76cff9e543 Mon Sep 17 00:00:00 2001 From: ImpressiveTaste <94606213+ImpressiveTaste@users.noreply.github.com> Date: Sat, 12 Feb 2022 10:08:02 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 21f1d3a..3094c38 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# pi-power-button +# pi-power-button - 3 seconds delay ## Details