-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmission12_build.ts
104 lines (85 loc) · 2.63 KB
/
mission12_build.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
// Add your code here
function myramp(startPower: number = 1, maxPowerLeft: number = 10, maxPowerRight: number = 10, increment: number = 1, time: number = 4) {
let leftPower = startPower;
let rightPower = startPower;
motors.largeBC.tank(leftPower, rightPower);
let startTime = control.timer1.millis();
while (true) {
if (leftPower < maxPowerLeft || rightPower < maxPowerRight) {
if (leftPower < maxPowerLeft) {
leftPower += increment;
}
if (rightPower < maxPowerRight) {
rightPower += increment;
}
brick.showValue("right:", rightPower, 1)
brick.showValue("left:", leftPower, 2)
motors.largeBC.tank(leftPower, rightPower);
}
pause(50);
if (control.timer1.millis() - startTime > 1000 * time) {
break;
}
if (exitFlag) {
exit();
return;
}
}
}
function mission12_build_a() {
myramp(1, 30, 30, 2, 2.5);
motors.largeBC.tank(25, 25);
let leftDetected = false;
let rightDetected = false;
while (true) {
if (sensors.color2.isColorDetected(ColorSensorColor.Red)) {
leftDetected = true;
}
if (sensors.color3.isColorDetected(ColorSensorColor.Red)) {
rightDetected = true;
}
if (rightDetected || leftDetected) {
break;
}
pause(5);
if (exitFlag) {
exit();
return;
}
}
motors.largeBC.stop();
motors.largeBC.tank(-75, -73, 5, MoveUnit.Rotations);
}
function mission12_build_b() {
myramp(1, 25, 25, 1, 2)
music.playSoundEffect(sounds.animalsCatPurr);
motors.largeBC.tank(25, 25);
while (true) {
if (sensors.color2.isColorDetected(ColorSensorColor.Blue) || sensors.color2.isColorDetected(ColorSensorColor.Blue)) {
break;
}
pause(5);
if (exitFlag) {
exitFlag = false;
return;
}
}
music.playSoundEffect(sounds.animalsElephantCall);
while (true) {
if (sensors.color3.isColorDetected(ColorSensorColor.Black) || sensors.color2.isColorDetected(ColorSensorColor.Black)) {
break;
}
pause(5);
if (exitFlag) {
exit();
return;
}
}
music.playSoundEffect(sounds.animalsCatPurr);
pause(250);
motors.largeBC.stop();
//pause(200);
motors.largeBC.tank(-75, -75, .25, MoveUnit.Rotations);
motors.largeBC.tank(-50, -75, 2, MoveUnit.Rotations);
// motors.largeBC.tank(50, -50, 1.5, MoveUnit.Rotations);
}