forked from xiaokaizh/SmartDoorControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeviceControl.py
More file actions
47 lines (38 loc) · 996 Bytes
/
DeviceControl.py
File metadata and controls
47 lines (38 loc) · 996 Bytes
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
#!/user/bin/env python
# coding=utf-8
__author__ = 'xzhao'
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO_open = 11 # 开门
GPIO_alert = 13 # 报警
GPIO_bell = 15 # 响铃
open = 0
alert = 0
bell = 0
def doorControl(open):
global GPIO_open
GPIO.setup(GPIO_open, GPIO.OUT)
if open == 1:
GPIO.setmode(GPIO.BOARD)
GPIO.output(GPIO_open, GPIO.LOW)
else:
GPIO.setmode(GPIO.BOARD)
GPIO.output(GPIO_open, GPIO.HIGH)
def alertControl(alert):
global GPIO_alert
GPIO.setup(GPIO_alert, GPIO.OUT)
if alert == 1:
GPIO.setmode(GPIO.BOARD)
GPIO.output(GPIO_alert, GPIO.LOW)
else:
GPIO.setmode(GPIO.BOARD)
GPIO.output(GPIO_alert, GPIO.HIGH)
def doorBell(bell):
global GPIO_bell
GPIO.setup(GPIO_bell, GPIO.OUT)
if bell == 1:
GPIO.setmode(GPIO.BOARD)
GPIO.output(GPIO_bell, GPIO.LOW)
else:
GPIO.setmode(GPIO.BOARD)
GPIO.output(GPIO_bell, GPIO.HIGH)