-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVernie.py
170 lines (132 loc) · 3.4 KB
/
Vernie.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
from pybricks.hubs import MoveHub
from pybricks.pupdevices import Motor, Remote, Light
from pybricks.parameters import Port, Stop, Button, Color
from pybricks.tools import wait
# INICIALIZAR -------------------------------------------------------
# Initialize the motors.
MotorA = Motor(Port.A);
MotorB = Motor(Port.B);
MotorC = Motor(Port.D);
# Initialize the hub.
hub = MoveHub()
hub.light.on(Color.ORANGE)
# Connect to the remote.
remote = Remote(timeout=None)
remote.light.on(Color.ORANGE)
# VARIABLES --------------------------------------------------------
global speed
speed = 50
global velocidad
velocidad = 1
global modalidad
modalidad = 1
global bailando
bailando = False
global vuelta
vuelta = 40
# MODALIDADES -------------------------------------------------------
# Cambiar modalidad
def cambiarModalidad():
global modalidad
if modalidad < 5:
modalidad += 1
else:
modalidad = 1
# Velocidades
if modalidad is 1:
remote.light.on(Color.ORANGE)
# Hablar
if modalidad is 2:
remote.light.on(Color.YELLOW)
# Bailar
if modalidad is 3:
remote.light.on(Color.CYAN)
# Disparo
if modalidad is 4:
remote.light.on(Color.RED)
# Apagar
if modalidad is 5:
remote.light.on(Color.NONE)
# Velocidades
def velocidades():
global velocidad
global speed
global vuelta
velocidad +=1
for x in range(velocidad):
remote.light.on(Color.NONE)
wait(100)
remote.light.on(Color.ORANGE)
if velocidad is 1:
speed = 50
vuelta = 40
if velocidad is 2:
speed = 100
vuelta = 50
if velocidad is 3:
speed = 150
vuelta = 75
velocidad = 0
def apagar():
MotorC.run_target(500, 0)
import minBtM
def disparo():
MotorC.run_target(1000, 105)
MotorC.run_target(1000, 0)
def hablar():
MotorC.run_target(500, -20)
MotorC.run_target(500, 20)
MotorC.run_target(500, 0, then=Stop.COAST)
def bailar():
if bailando == False:
bailando == True
baile()
elif bailando == True:
bailando == False
def baile():
MotorA.run_angle(300, 90, wait=False)
MotorB.run_angle(300, 90)
wait(100)
MotorA.run_angle(300, -90, wait=False)
MotorB.run_angle(300, -90)
wait(100)
# CONTROLES ---------------------------------------------------------
while True:
pressed = remote.buttons.pressed()
drive_speed_A = 0
drive_speed_B = 0
if Button.LEFT_PLUS in pressed:
drive_speed_A -= speed
drive_speed_B += speed
if Button.LEFT_MINUS in pressed:
drive_speed_A += speed
drive_speed_B -= speed
if Button.RIGHT_PLUS in pressed:
drive_speed_A -= vuelta
drive_speed_B -= vuelta
if Button.RIGHT_MINUS in pressed:
drive_speed_A += vuelta
drive_speed_B += vuelta
if Button.CENTER in pressed:
cambiarModalidad()
wait(250)
if Button.RIGHT in pressed:
if modalidad is 1:
velocidades()
if modalidad is 2:
hablar()
if modalidad is 3:
bailar()
if modalidad is 4:
disparo()
if modalidad is 5:
apagar()
wait(250)
if drive_speed_A != 0:
MotorA.dc(drive_speed_A)
MotorB.dc(drive_speed_B)
else:
MotorA.stop()
MotorB.stop()
# Wait.
wait(10)