-
Notifications
You must be signed in to change notification settings - Fork 13
/
test.ts
95 lines (94 loc) · 4.01 KB
/
test.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
CutebotPro.irCallback(function () {
if (CutebotPro.irButton(CutbotProIRButtons.Up)) {
CutebotPro.distanceRunning(CutebotProOrientation.Advance, 10, CutebotProDistanceUnits.Cm)
}
if (CutebotPro.irButton(CutbotProIRButtons.Menu)) {
CutebotPro.fullSpeedAhead()
}
if (CutebotPro.irButton(CutbotProIRButtons.Zero)) {
led.plot(0, 0)
k = 1
}
})
// tests go here; this will not be compiled when this package is used as an extension.
input.onButtonPressed(Button.A, function () {
i += 1
if (i == 1) {
CutebotPro.colorLight(CutebotProRGBLight.RGBA, 0xff0000)
}
if (i == 2) {
CutebotPro.colorLight(CutebotProRGBLight.RGBA, 0x00ff00)
}
if (i == 3) {
CutebotPro.colorLight(CutebotProRGBLight.RGBA, 0x0000ff)
i = 0
}
})
input.onButtonPressed(Button.B, function () {
j += 1
if (j == 1) {
pins.digitalWritePin(DigitalPin.P1, 1)
pins.digitalWritePin(DigitalPin.P2, 0)
pins.digitalWritePin(DigitalPin.P13, 0)
pins.digitalWritePin(DigitalPin.P14, 0)
}
if (j == 2) {
pins.digitalWritePin(DigitalPin.P1, 0)
pins.digitalWritePin(DigitalPin.P2, 1)
pins.digitalWritePin(DigitalPin.P13, 0)
pins.digitalWritePin(DigitalPin.P14, 0)
}
if (j == 3) {
pins.digitalWritePin(DigitalPin.P1, 0)
pins.digitalWritePin(DigitalPin.P2, 0)
pins.digitalWritePin(DigitalPin.P13, 1)
pins.digitalWritePin(DigitalPin.P14, 0)
}
if (j == 4) {
pins.digitalWritePin(DigitalPin.P1, 0)
pins.digitalWritePin(DigitalPin.P2, 0)
pins.digitalWritePin(DigitalPin.P13, 0)
pins.digitalWritePin(DigitalPin.P14, 1)
j = 0
}
})
let j = 0
let i = 0
let k = 0
music.setBuiltInSpeakerEnabled(false)
basic.pause(100)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S1, 0)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S2, 0)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S3, 0)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S4, 0)
basic.pause(500)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S1, 180)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S2, 180)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S3, 180)
CutebotPro.extendServoControl(ServoType.Servo180, CutebotProServoIndex.S4, 180)
basic.pause(500)
k = 0
i = 0
j = 0
music.playTone(262, music.beat(BeatFraction.Half))
basic.forever(function () {
if (CutebotPro.ultrasonic(SonarUnit.Centimeters) <= 5) {
CutebotPro.pwmCruiseControl(0, 0)
}
if (k == 0) {
CutebotPro.extendMotorControl(100)
} else if (k == 1) {
for (let index = 0; index < 10000; index++) {
CutebotPro.trackbitStateValue()
if (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_7) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_9) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_11) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_8) || CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_3))))) {
CutebotPro.pwmCruiseControl(0, 70)
} else if (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_6) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_13) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_14) || (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_12) || CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_2))))) {
CutebotPro.pwmCruiseControl(70, 0)
} else if (CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_5) || CutebotPro.getGrayscaleSensorState(TrackbitStateType.Tracking_State_1)) {
CutebotPro.pwmCruiseControl(50, 50)
}
}
CutebotPro.pwmCruiseControl(0, 0)
k = 0
}
})