-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcrash.py
More file actions
39 lines (27 loc) · 728 Bytes
/
crash.py
File metadata and controls
39 lines (27 loc) · 728 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
from microbit import *
class CRASH(object):
"""基本描述
碰撞传感器
Args:
pin: 连接端口
"""
def __init__(self, pin):
self.__pin = pin
self.__pin.set_pull(self.__pin.PULL_UP)
def crash_is_pressed(self) -> bool:
"""基本描述
碰撞传感器被按下
Returns:
boolean: 按下返回True, 未按下返回False
"""
if self.__pin.read_digital() == 0:
return True
else:
return False
if __name__ == '__main__':
button = CRASH(pin1)
while True:
if button.crash_is_pressed():
display.show(Image.HAPPY)
else:
display.show(Image.SAD)