From 367b1a10db14149e32d251142966c051f5a604c7 Mon Sep 17 00:00:00 2001 From: +++ Date: Tue, 8 Sep 2020 17:56:24 +0200 Subject: [PATCH] =?UTF-8?q?initialer=20commit=20der=20pin-=C3=BCberwachung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- watchdoor.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 watchdoor.py diff --git a/watchdoor.py b/watchdoor.py new file mode 100644 index 0000000..bfaa17a --- /dev/null +++ b/watchdoor.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +#coding: utf8 + +# file: watchdoor.py +# date: 06.09.2020 +# mail: berhsi@web.de +# desc: deamon who deals with edge detection at pin 18 + +import time +import logging +import RPi.GPIO as GPIO + +loglevel = logging.INFO +formatstring = '%(asctime)s: %(levelname)s: %(message)s' +logging.basicConfig(format=formatstring, level=loglevel) + +GPIO.setmode(GPIO.BOARD) # kind of enumeration +GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) # pin 18 (GPIO 24) +channel = 18 + +def voltage_changed(channel): + ''' + callback-function + ''' + if GPIO.input(channel) == GPIO.HIGH: + # door closed -> pin hight + logging.info('Pin high triggered - Space closed') + else: + # door open -> pin low + logging.info('Pin low triggered - Space is open') + +def main(): + ''' + ''' + logging.info('watchdoor.py started') + GPIO.add_event_detect(channel, + GPIO.BOTH, + callback = voltage_changed, + bouncetime = 200) + while 1: + time.sleep(0.1) + + +if __name__ == '__main__': + main()