-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
31 lines (30 loc) · 830 Bytes
/
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
twist.setColor(63, 255, 0, 0)
motobit.enable(MotorPower.On)
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 0)
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 0)
let was = 0
basic.forever(function () {
basic.showNumber(was)
basic.pause(100)
})
basic.forever(function () {
let c = twist.getCount(63)
if (c != was) {
was = c
if (c > 0) {
twist.setColor(63, 0, 255, 0)
}
else if (c < 0) {
twist.setColor(63, 0, 0, 255)
}
else {
twist.setColor(63, 255, 0, 0)
}
if (c >= 0) {
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, c)
}
else {
motobit.setMotorSpeed(Motor.Right, MotorDirection.Reverse, c)
}
}
})