init
This commit is contained in:
commit
ce1095bb24
27 changed files with 621 additions and 0 deletions
21
app/utils/gpio_handler.py
Normal file
21
app/utils/gpio_handler.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from gpiozero import Button
|
||||
from signal import pause
|
||||
import time
|
||||
|
||||
class Lichtschranke:
|
||||
def __init__(self, gpio_pin, callback, schutzzeit=3):
|
||||
self.pin = gpio_pin
|
||||
self.callback = callback
|
||||
self.last_trigger = 0
|
||||
self.button = Button(gpio_pin, pull_up=False, bounce_time=0.05)
|
||||
self.button.when_pressed = self._ausgeloest
|
||||
self.schutzzeit = schutzzeit
|
||||
|
||||
def _ausgeloest(self):
|
||||
jetzt = time.time()
|
||||
if jetzt - self.last_trigger > self.schutzzeit:
|
||||
self.last_trigger = jetzt
|
||||
self.callback()
|
||||
|
||||
def stop(self):
|
||||
self.button.close()
|
||||
Reference in a new issue