#!/usr/bin/env python
#coding: utf8
import time
import RPi.GPIO as GPIO
channel = 17
channel2 = 4
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(channel, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(channel2, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(26,GPIO.OUT)
GPIO.setup(21,GPIO.OUT)
GPIO.setup(20,GPIO.OUT)
GPIO.setup(19,GPIO.OUT)
GPIO.setup(16,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
# Status der Relays setzen
GPIO.output(26,GPIO.LOW)
GPIO.output(21,GPIO.LOW)
GPIO.output(20,GPIO.LOW)
GPIO.output(19,GPIO.LOW)
GPIO.output(16,GPIO.LOW)
GPIO.output(13,GPIO.LOW)
GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime = 2000)
GPIO.add_event_detect(channel2, GPIO.BOTH, bouncetime = 2000)
lastState = 0
while True:
state = GPIO.input(channel)
# Wenn sich nichts am Melder getan hat,
# dann kurz schlafen und den Melder direkt wieder abfragen
if lastState == state:
time.sleep(0.5)
next
# aktuellen Status merken
lastState = state
if state == 1:
GPIO.output(13, GPIO.HIGH)
GPIO.output(19, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(16, GPIO.HIGH)
GPIO.output(26, GPIO.HIGH)
time.sleep(1)
GPIO.output(20, GPIO.HIGH)
GPIO.output(21, GPIO.HIGH)
else:
GPIO.output(21, GPIO.LOW)
GPIO.output(20, GPIO.LOW)
time.sleep(1)
GPIO.output(26, GPIO.LOW)
GPIO.output(16, GPIO.LOW)
time.sleep(0.5)
GPIO.output(19, GPIO.LOW)
GPIO.output(13, GPIO.LOW)
lastState2 = 1
while True:
state2 = GPIO.input(channel2)
# Wenn sich nichts am Melder getan hat,
# dann kurz schlafen und den Melder direkt wieder abfragen
if lastState2 == state2:
time.sleep(0.5)
next
# aktuellen Status merken
lastState2 = state2
if state2 == 1:
GPIO.output(21, GPIO.HIGH)
GPIO.output(20, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(16, GPIO.HIGH)
GPIO.output(26, GPIO.HIGH)
time.sleep(1)
GPIO.output(19, GPIO.HIGH)
GPIO.output(13, GPIO.HIGH)
else:
GPIO.output(19, GPIO.LOW)
GPIO.output(13, GPIO.LOW)
time.sleep(1)
GPIO.output(26, GPIO.LOW)
GPIO.output(16, GPIO.LOW)
time.sleep(0.5)
GPIO.output(21, GPIO.LOW)
GPIO.output(20, GPIO.LOW)