From e47caa28d25fc133de7f57332738d063773800af Mon Sep 17 00:00:00 2001 From: Philipp Clima Date: Tue, 20 Aug 2019 14:21:53 +0200 Subject: [PATCH] =?UTF-8?q?Urspr=C3=BCngliche=20Datein=20von=20RaspberryPi?= =?UTF-8?q?=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- onoff.py | 38 ++++++++++++++++++++++++++++++++++++++ start.py | 22 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 onoff.py create mode 100644 start.py diff --git a/onoff.py b/onoff.py new file mode 100644 index 0000000..01941a3 --- /dev/null +++ b/onoff.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +import RPi.GPIO as GPIO +import time, os, sys + +GPIO.setmode(GPIO.BOARD) + +input_pin = 36 + +GPIO.setup(input_pin, GPIO.IN) + +a=0 + +# solange "wahr" gilt (immer!) wird folgende sequenz ausgeführt: +# wird der input pin als high (3V) erkannt, wird 60x alle 0.05 sekunden überprüft +# ob der pin wieder auf low (0V) zurückgesetzt wird. ist dies der fall, wird ein reboot ausgeführt. +# ist nach diesen 60x0.05 sekunden der pin immernoch high, wird ein poweroff ausgeführt. + +# rein theorethisch wäre es möglich innerhalb der 0.05 sekunden wartezeit nach der überprüfung auf low +# den schalter loszulassen, und somit würde weder ein reboot noch ein shutdown ausgeführt werden. +# sollte das zu oft passieren bitte das time.sleep innerhalb der (while a) schleife auf 0.001 sekunden stellen, +# dafür aber a auf 3000. + +while True: + print("State:", GPIO.input(input_pin)) + if GPIO.input(input_pin) == GPIO.HIGH: + while a <= 60: + if GPIO.input(input_pin) == GPIO.LOW: + print("reboot") + time.sleep(2) + os.system("reboot") + a=a+1 + time.sleep(0.05) + if GPIO.input(input_pin) == GPIO.HIGH: + print("poweroff") + time.sleep(2) + os.system("poweroff") + time.sleep(0.05) \ No newline at end of file diff --git a/start.py b/start.py new file mode 100644 index 0000000..7eee575 --- /dev/null +++ b/start.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +import RPi.GPIO as GPIO +import time + +GPIO.setmode(GPIO.BOARD) + +input_pin = 3 + +GPIO.setup(input_pin, GPIO.IN) + +while True: + if not(GPIO.input(input_pin)): + time.sleep(1) + #starte externen timer + #starte externen zähler + + + #Endpunkt: timer wird gespeichert und das externe programm beendet + #zähler wird gespeichert und zurückgesetzt + + #Score wird gespeichert und geliestet \ Score tabbel wird ca. 8sek. lang angezeigt