-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
118 lines (109 loc) · 3.05 KB
/
main.ts
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
bluetooth.onBluetoothConnected(function () {
basic.showLeds(`
. . # # .
# . # . #
. # # # .
# . # . #
. . # # .
`)
})
bluetooth.onBluetoothDisconnected(function () {
basic.showIcon(IconNames.No)
})
function SetMotors () {
FR = DirY + DirX + RotZ
FL = DirY - DirX - RotZ
BR = DirY - DirX + RotZ
BL = DirY + DirX - RotZ
robotbit.GeekServo(robotbit.Servos.S1, FR + 90)
robotbit.GeekServo(robotbit.Servos.S2, 90 - FL)
robotbit.GeekServo(robotbit.Servos.S3, BR + 90)
robotbit.GeekServo(robotbit.Servos.S4, 90 - BL)
basic.pause(50)
}
control.onEvent(EventBusSource.MES_DPAD_CONTROLLER_ID, EventBusValue.MICROBIT_EVT_ANY, function () {
if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_1_DOWN) {
DirY = Speed
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_1_UP) {
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_2_DOWN) {
DirY = 0 - Speed
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_2_UP) {
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_3_DOWN) {
DirX = 0 - Speed
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_3_UP) {
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_4_DOWN) {
DirX = Speed
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_4_UP) {
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_A_DOWN) {
DirX = 0
DirY = 0
RotZ = 0
basic.showArrow(ArrowNames.North)
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_A_UP) {
basic.clearScreen()
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_B_DOWN) {
DirX = 0
DirY = 0
RotZ = 0
basic.showArrow(ArrowNames.South)
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_B_UP) {
basic.clearScreen()
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_C_DOWN) {
if (DirX != 0 && DirY != 0) {
} else {
RotZ = 0 - Speed
}
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_C_UP) {
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_D_DOWN) {
if (DirX != 0 && DirY != 0) {
} else {
RotZ = Speed
}
} else if (control.eventValue() == EventBusValue.MES_DPAD_BUTTON_D_UP) {
} else {
}
})
let BL = 0
let BR = 0
let FL = 0
let FR = 0
let RotZ = 0
let DirX = 0
let DirY = 0
let Speed = 0
Speed = 60
basic.showLeds(`
. # . . .
. # # . .
. # # # .
. # # . .
. # . . .
`)
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.clearScreen()
basic.forever(function () {
SetMotors()
})