-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
123 lines (118 loc) · 3.17 KB
/
main.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
def on_bluetooth_connected():
basic.show_leds("""
. . # # .
# . # . #
. # # # .
# . # . #
. . # # .
""")
bluetooth.on_bluetooth_connected(on_bluetooth_connected)
def on_bluetooth_disconnected():
basic.show_icon(IconNames.NO)
bluetooth.on_bluetooth_disconnected(on_bluetooth_disconnected)
def SetMotors():
global FR, FL, BR, BL
FR = DirY + DirX + RotZ
FL = DirY - DirX - RotZ
BR = DirY - DirX + RotZ
BL = DirY + DirX - RotZ
robotbit.geek_servo(robotbit.Servos.S1, FR + 90)
robotbit.geek_servo(robotbit.Servos.S2, 90 - FL)
robotbit.geek_servo(robotbit.Servos.S3, BR + 90)
robotbit.geek_servo(robotbit.Servos.S4, 90 - BL)
basic.pause(50)
def on_mes_dpad_controller_id_microbit_evt():
global DirY, DirX, RotZ
if control.event_value() == EventBusValue.MES_DPAD_BUTTON_1_DOWN:
DirY = Speed
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_1_UP:
pass
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_2_DOWN:
DirY = 0 - Speed
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_2_UP:
pass
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_3_DOWN:
DirX = 0 - Speed
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_3_UP:
pass
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_4_DOWN:
DirX = Speed
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_4_UP:
pass
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_A_DOWN:
DirX = 0
DirY = 0
RotZ = 0
basic.show_arrow(ArrowNames.NORTH)
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_A_UP:
basic.clear_screen()
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_B_DOWN:
DirX = 0
DirY = 0
RotZ = 0
basic.show_arrow(ArrowNames.SOUTH)
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_B_UP:
basic.clear_screen()
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_C_DOWN:
if DirX != 0 and DirY != 0:
pass
else:
RotZ = 0 - Speed
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_C_UP:
pass
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_D_DOWN:
if DirX != 0 and DirY != 0:
pass
else:
RotZ = Speed
elif control.event_value() == EventBusValue.MES_DPAD_BUTTON_D_UP:
pass
else:
pass
control.on_event(EventBusSource.MES_DPAD_CONTROLLER_ID,
EventBusValue.MICROBIT_EVT_ANY,
on_mes_dpad_controller_id_microbit_evt)
BL = 0
BR = 0
FL = 0
FR = 0
RotZ = 0
DirX = 0
DirY = 0
Speed = 0
Speed = 60
basic.show_leds("""
. # . . .
. # # . .
. # # # .
. # # . .
. # . . .
""")
DirY = Speed
SetMotors()
DirY = 0
SetMotors()
DirY = 0 - Speed
SetMotors()
DirY = 0
SetMotors()
DirX = Speed
SetMotors()
DirX = 0
SetMotors()
DirX = 0 - Speed
SetMotors()
DirX = 0
SetMotors()
RotZ = Speed
SetMotors()
RotZ = 0
SetMotors()
RotZ = 0 - Speed
SetMotors()
RotZ = 0
SetMotors()
basic.clear_screen()
def on_forever():
SetMotors()
basic.forever(on_forever)