forked from cpswan/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalarm.py
More file actions
57 lines (56 loc) · 2.53 KB
/
alarm.py
File metadata and controls
57 lines (56 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup (11, GPIO.IN)
GPIO.setup (12, GPIO.OUT)
GPIO.setup (13, GPIO.IN)
GPIO.setup (15, GPIO.OUT)
while True:
if not GPIO.input(11):
if GPIO.input(13):
print "The door is open - please close the door and try again."
GPIO.output(15, True)
time.sleep(.3)
GPIO.output(15, False)
flash = 3
while flash > 0:
GPIO.output(12, True)
time.sleep(.3)
GPIO.output(12, False)
time.sleep(.3)
flash -= 1
else:
active = 'true'
activated = 'false'
time.sleep(.1)
if GPIO.input(11):
print "Alarm Armed"
while active == 'true':
GPIO.output(12,False)
if not GPIO.input(11):
time.sleep(.1)
if GPIO.input(11):
print "Alarm Disarmed"
time.sleep(.1)
active = 'false'
if GPIO.input(13):
print "**** Alarm !!! ****"
activated = 'true'
GPIO.output(15, True)
time.sleep(10)
GPIO.output(15, False)
while activated == 'true':
if not GPIO.input(11):
time.sleep(.1)
if GPIO.input(11):
print "Alarm Disarmed"
time.sleep(.1)
active = 'false'
activated = 'false'
else:
GPIO.output(12, True)
time.sleep(.3)
GPIO.output(12, False)
time.sleep(.3)
else:
GPIO.output(12,True)