-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathlight.py
More file actions
36 lines (26 loc) · 751 Bytes
/
light.py
File metadata and controls
36 lines (26 loc) · 751 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
from microbit import *
class LIGHT(object):
"""基本描述
环境光传感器,返回lux
Args:
pin: 连接端口
Returns:
value: 光线强度 0-16000lux
"""
def __init__(self, pin):
self.__pin = pin
def get_lightlevel(self):
"""基本描述
环境光传感器,返回lux
Returns:
value: 光强度单位勒克司Lux
"""
__value = self.__pin.read_analog()
if __value <= 200:
return ((__value - 45) * (1600 - 0)) / (200 - 45) + 0
else:
return ((__value - 200) * (14000 - 1600)) / (1023 - 200) + 1600
if __name__ == "__main__":
s = LIGHT(pin1)
while True:
print(s.get_lightlevel())