-
Notifications
You must be signed in to change notification settings - Fork 4
/
pir.py
46 lines (34 loc) · 927 Bytes
/
pir.py
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
from microbit import *
from enum import *
class PIR(object):
"""基本描述
人体红外检测, 运动检测
Args:
RJ_pin (pin): 连接端口
"""
def __init__(self, RJ_pin):
if RJ_pin == J1:
self.__pin = pin8
elif RJ_pin == J2:
self.__pin = pin12
elif RJ_pin == J3:
self.__pin = pin14
elif RJ_pin == J4:
self.__pin = pin16
def PIR_is_decection(self) -> bool:
"""基本描述
检测到人体或者运动
Returns:
boolean: 检测到返回True, 未检测返回False
"""
if self.__pin.read_digital():
return True
else:
return False
if __name__ == '__main__':
sensor = PIR(J1)
while True:
if sensor.PIR_is_decection():
display.show(Image.HAPPY)
else:
display.show(Image.SAD)