-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfans.py
46 lines (34 loc) · 1013 Bytes
/
fans.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 FANS(object):
"""基本描述
设置风扇运动模式
Args:
RJ_pin (pin): 连接端口
"""
def __init__(self, RJ_pin):
if RJ_pin == J1:
self.__pin = pin1
elif RJ_pin == J2:
self.__pin = pin2
elif RJ_pin == J3:
self.__pin = pin13
elif RJ_pin == J3:
self.__pin = pin15
def set_fans(self, state, speed=100):
"""基本描述
启动或者停止电机
Args:
state (numbers): 1运转 0停止
speed (numbers): 速度百分比,state为1时使能 0-100
"""
if state == 0:
self.__pin.write_analog(0)
elif state == 1:
speed = ((speed - 0) * (1023 - 0)) / (100 - 0) + 0;
self.__pin.write_analog(speed)
else:
print("speed error,must 0 <= brightness <= 100")
if __name__ == "__main__":
f = FANS(J1)
f.set_fans(1, 80)