Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- from time import time
- from time import sleep
- GPIO.setmode(GPIO.BOARD)
- doorSwitch = 11
- buzzer = 15
- GPIO.setup(doorSwitch, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(buzzer, GPIO.OUT)
- GPIO.output(buzzer, 0)
- doorStatus = 0
- openTime = time()
- try:
- while True:
- if GPIO.input(doorSwitch) == 1 and doorStatus == 0:
- openTime = time()
- doorStatus = 1
- print("Door is Open")
- if GPIO.input(doorSwitch) == 1 and doorStatus == 1:
- if time() - openTime >= 120:
- print("Open 2 minutes")
- GPIO.output(buzzer, 1)
- sleep(5)
- GPIO.output(buzzer, 0)
- sleep(1)
- if time() - openTime >= 30 and time() - openTime < 120:
- print("Open 30 seconds")
- GPIO.output(buzzer, 1)
- sleep(1)
- GPIO.output(buzzer, 0)
- sleep(3)
- if GPIO.input(doorSwitch) == 0 and doorStatus == 1:
- doorStatus = 0
- GPIO.output(buzzer, 0)
- print("Door is Closed")
- except KeyboardInterrupt:
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement