-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.py
executable file
·101 lines (72 loc) · 1.78 KB
/
base.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B # , MoveTank, SpeedPercent
from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3
from ev3dev2.sensor.lego import TouchSensor, ColorSensor
from ev3dev2.sound import Sound
##################
# #
# SETTINGS #
# #
##################
###################
# #
# CONSTANTS #
# #
###################
SOUND_VOLUME = 100
LEFT = 0
RIGHT = 1
#####################
# #
# PERIPHERALS #
# #
#####################
sound = Sound()
button = TouchSensor(INPUT_3)
left_motor = LargeMotor(OUTPUT_A)
right_motor = LargeMotor(OUTPUT_B)
motors = [left_motor, right_motor]
left_sensor = ColorSensor(INPUT_1)
right_sensor = ColorSensor(INPUT_2)
sensors = [left_sensor, right_sensor]
# move_tank = MoveTank(OUTPUT_A, OUTPUT_B)
######################
# #
# MAIN PROGRAM #
# #
######################
def speak(message: str) -> None:
sound.speak(message)
print(message)
def work() -> None:
while True:
if button.is_pressed:
handle_button_pressed()
else:
try:
iterate()
except Exception as e:
print(e)
def handle_button_pressed() -> None:
stop()
speak('STOP')
button.wait_for_released()
button.wait_for_bump()
speak('START')
def iterate() -> None:
pass
def stop() -> None:
for motor in motors:
motor.stop()
def main() -> None:
sound.set_volume(SOUND_VOLUME)
speak('READY')
button.wait_for_bump()
speak('START')
try:
work()
except KeyboardInterrupt as e:
stop()
raise e
if __name__ == '__main__':
main()