replacing loops.pause -> pause, loops.forever -> forever

This commit is contained in:
Peli de Halleux 2018-02-14 16:05:31 -08:00
parent 0384eb4d9d
commit daa88b299d
62 changed files with 151 additions and 151 deletions

View File

@ -3,6 +3,6 @@
### #specific
```cards
loops.forever(() => {});
loops.pause(0)
forever(() => {});
pause(0)
```

View File

@ -7,6 +7,6 @@ while (true) {
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
}
loops.pause(1);
pause(1);
}
```

View File

@ -8,6 +8,6 @@ while (true) {
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
}
loops.pause(1);
pause(1);
}
```

View File

@ -3,7 +3,7 @@
```blocks
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
brick.showImage(images.objectsLightOn)
loops.pause(5000)
pause(5000)
brick.clearScreen()
})
```

View File

@ -1,9 +1,9 @@
# Reverse Beeper Activity 1
```blocks
loops.forever(function () {
forever(function () {
music.playTone(440, sensors.ultrasonic4.distance());
loops.pause(50)
pause(50)
})
motors.largeBC.setSpeed(-20);
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);

View File

@ -1,10 +1,10 @@
# Reverse Beeper Activity 2
```blocks
loops.forever(function () {
forever(function () {
if (motors.largeB.speed() != 0 && sensors.ultrasonic4.distance() < 20) {
music.playTone(440, sensors.ultrasonic4.distance());
loops.pause(50)
pause(50)
}
})
motors.largeBC.setSpeed(-20);

View File

@ -13,7 +13,7 @@ control.runInParallel(function () {
while (beep) {
if (sensors.ultrasonic4.distance() < 20) {
music.playTone(440, sensors.ultrasonic4.distance())
loops.pause(50)
pause(50)
}
}
})

View File

@ -5,10 +5,10 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
motors.largeBC.setSpeed(50)
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
motors.largeBC.setSpeed(0)
loops.pause(1000)
pause(1000)
brick.setStatusLight(StatusLight.OrangeFlash)
motors.largeBC.setSpeed(-50)
loops.pause(2000)
pause(2000)
motors.largeBC.setSpeed(0)
})
```

View File

@ -6,10 +6,10 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
motors.largeBC.setSpeed(50)
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
motors.largeBC.setSpeed(0)
loops.pause(1000)
pause(1000)
brick.setStatusLight(StatusLight.OrangeFlash)
motors.largeBC.setSpeed(-50)
loops.pause(2000)
pause(2000)
motors.largeBC.setSpeed(0)
})
```

View File

@ -9,11 +9,11 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
brick.showImage(images.eyesTiredMiddle)
motors.largeBC.setSpeed(0)
loops.pause(1000)
pause(1000)
brick.setStatusLight(StatusLight.OrangeFlash)
brick.showImage(images.eyesDizzy)
motors.largeBC.setSpeed(-50)
loops.pause(2000)
pause(2000)
motors.largeBC.setSpeed(0)
})
```

View File

@ -15,7 +15,7 @@ brick.buttonDown.onEvent(ButtonEvent.Bumped, function () {
drive.push(5)
})
pauseUntil(() => drive.length >= 5)
loops.pause(1000)
pause(1000)
music.playSoundEffectUntilDone(sounds.communicationGo)
for (let d of drive) {
if (d == 1) {

View File

@ -19,7 +19,7 @@ brick.buttonDown.onEvent(ButtonEvent.Bumped, function () {
music.playSoundEffectUntilDone(sounds.systemClick)
})
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped);
loops.pause(1000)
pause(1000)
music.playSoundEffectUntilDone(sounds.communicationGo)
for (let d of drive) {
if (d == 1) {

View File

@ -3,10 +3,10 @@
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
motors.largeBC.tank(75, 30)
loops.pause(1500)
pause(1500)
motors.largeBC.tank(-30, -75)
loops.pause(1000)
pause(1000)
motors.largeBC.tank(50, 50)
loops.pause(3000)
pause(3000)
})
```

View File

@ -3,12 +3,12 @@
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
motors.largeBC.tank(75, 30)
loops.pause(1500)
pause(1500)
motors.largeBC.tank(-30, -75)
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.largeBC.tank(0, 0)
loops.pause(1000)
pause(1000)
motors.largeBC.tank(50, 50)
loops.pause(3000)
pause(3000)
})
```

View File

@ -3,13 +3,13 @@
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
motors.largeBC.tank(75, 30)
loops.pause(1500)
pause(1500)
motors.largeBC.tank(-30, -75)
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.largeBC.tank(0, 0)
music.playSoundEffect(sounds.animalsDogBark1)
loops.pause(1000)
pause(1000)
motors.largeBC.tank(50, 50)
loops.pause(3000)
pause(3000)
})
```

View File

@ -1,7 +1,7 @@
# Traffic Lights Activity 3
```blocks
loops.forever(function () {
forever(function () {
if (sensors.color3.light(LightIntensityMode.Reflected) < 15) {
motors.largeBC.tank(30, 12)
} else {

View File

@ -127,7 +127,7 @@ sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
} else {
controlSteering = -70
}
loops.pause(4000)
pause(4000)
music.playTone(2000, 100)
controlSteering = 0
controlDrive = oldControlDrive
@ -162,7 +162,7 @@ sensors.color1.onColorDetected(ColorSensorColor.White, function () {
})
timestep = 0.014
// main loop
loops.forever(function () {
forever(function () {
reset()
while (!fallen) {
control.timer3.pauseUntil(5)

View File

@ -36,7 +36,7 @@ function RST() {
sensors.gyro2.reset()
sensors.gyro2.rate()
control.timer2.reset()
loops.pause(5000)
pause(5000)
mSum = 0;
mPos = 0;
mD = 0;
@ -65,7 +65,7 @@ function OS() {
gSum = gyro;
gMx = Math.max(gMx, gyro)
gMn = Math.min(gMn, gyro)
loops.pause(4);
pause(4);
}
} while (gMx - gMn > 2);
gOS = gSum / 200;
@ -121,7 +121,7 @@ function CHK() {
}
// M
loops.forever(function () {
forever(function () {
RST();
brick.showImage(images.eyesSleeping)
OS()
@ -142,7 +142,7 @@ loops.forever(function () {
CHK()
let t2 = control.timer1.millis();
let p = 5 - (t2 - t1);
loops.pause(Math.max(1, p))
pause(Math.max(1, p))
}
motors.stopAll()
st = 0;
@ -154,7 +154,7 @@ loops.forever(function () {
})
// BHV
loops.forever(function () {
forever(function () {
switch (st) {
case 0:
Cdrv = 0;
@ -162,7 +162,7 @@ loops.forever(function () {
break;
case 1:
Cdrv = 40;
loops.pause(4000);
pause(4000);
Cdrv = 0;
music.playTone(1000, 100);
st = 2;
@ -203,13 +203,13 @@ loops.forever(function () {
Cstr = 70;
else
Cstr = -70;
loops.pause(4000);
pause(4000);
music.playTone(2000, 100)
Cstr = 0;
Cdrv = oldDr;
}
break;
}
loops.pause(80);
pause(80);
})
```

View File

@ -21,7 +21,7 @@ let GTO = 0;
function DN() {
motors.largeAD.setBrake(true);
motors.largeAD.tank(50, 50, 1, MoveUnit.Seconds);
loops.pause(100);
pause(100);
motors.largeA.clearCounts()
motors.largeD.clearCounts()
}
@ -100,7 +100,7 @@ function UP() {
pauseUntil(() => motors.largeA.angle() < -65);
motors.largeA.stop();
loops.pause(500);
pause(500);
}
}
@ -277,7 +277,7 @@ function NGR() {
IS(4)
music.playSoundEffect(sounds.animalsDogGrowl);
UP();
loops.pause(1500);
pause(1500);
music.stopAllSounds()
music.playSoundEffect(sounds.animalsDogBark1)
P_C--;
@ -303,11 +303,11 @@ function PPP() {
NS = false;
IS(2);
UP();
loops.pause(100)
pause(100)
motors.largeA.setSpeed(-30, 70, MoveUnit.Degrees);
loops.pause(800);
pause(800);
music.playSoundEffect(sounds.mechanicalHorn1);
loops.pause(1000);
pause(1000);
for(let i = 0; i < 3; ++i) {
motors.largeA.setSpeed(-30, 20, MoveUnit.Degrees);
motors.largeA.setSpeed(30, 20, MoveUnit.Degrees);
@ -324,10 +324,10 @@ function HPY() {
for(let i = 0; i < 3; ++i) {
music.playSoundEffect(sounds.animalsDogBark1);
motors.largeAD.setSpeed(-100, 0.2, MoveUnit.Seconds);
loops.pause(300)
pause(300)
motors.largeAD.setSpeed(10, 0.3, MoveUnit.Seconds)
}
loops.pause(500);
pause(500);
music.stopAllSounds();
DN();
RST();
@ -347,7 +347,7 @@ function WKU() {
MHT(0)
DN()
STL()
loops.pause(1000);
pause(1000);
UP()
CS(0;)
}
@ -358,7 +358,7 @@ MNRH();
IS(1);
UP();
RST();
loops.forever(function () {
forever(function () {
MON();
switch (DB_S) {
case 0:

View File

@ -18,7 +18,7 @@ function INI() {
INI()
let down = false;
loops.forever(function () {
forever(function () {
brick.showImage(images.informationQuestionMark)
brick.setStatusLight(StatusLight.OrangePulse);
pauseUntil(() => (down = brick.buttonDown.wasPressed()) || brick.buttonUp.wasPressed())

View File

@ -18,7 +18,7 @@ function INI() {
INI()
let down = false;
loops.forever(function () {
forever(function () {
brick.showImage(images.informationQuestionMark)
brick.setStatusLight(StatusLight.OrangePulse);
pauseUntil(() => (down = brick.buttonDown.wasPressed()) || brick.buttonUp.wasPressed())

View File

@ -36,7 +36,7 @@ function RST() {
sensors.gyro2.reset()
sensors.gyro2.rate()
control.timer2.reset()
loops.pause(5000)
pause(5000)
mSum = 0;
mPos = 0;
mD = 0;
@ -65,7 +65,7 @@ function OS() {
gSum = gyro;
gMx = Math.max(gMx, gyro)
gMn = Math.min(gMn, gyro)
loops.pause(4);
pause(4);
}
} while (gMx - gMn > 2);
gOS = gSum / 200;
@ -121,7 +121,7 @@ function CHK() {
}
// M
loops.forever(function () {
forever(function () {
RST();
brick.showImage(images.eyesSleeping)
OS()
@ -142,7 +142,7 @@ loops.forever(function () {
CHK()
let t2 = control.timer1.millis();
let p = 5 - (t2 - t1);
loops.pause(Math.max(1, p))
pause(Math.max(1, p))
}
motors.stopAll()
st = 0;
@ -154,7 +154,7 @@ loops.forever(function () {
})
// BHV
loops.forever(function () {
forever(function () {
switch (st) {
case 0:
Cdrv = 0;
@ -162,7 +162,7 @@ loops.forever(function () {
break;
case 1:
Cdrv = 40;
loops.pause(4000);
pause(4000);
Cdrv = 0;
music.playTone(1000, 100);
st = 2;
@ -203,13 +203,13 @@ loops.forever(function () {
Cstr = 70;
else
Cstr = -70;
loops.pause(4000);
pause(4000);
music.playTone(2000, 100)
Cstr = 0;
Cdrv = oldDr;
}
break;
}
loops.pause(80);
pause(80);
})
```

View File

@ -26,9 +26,9 @@ while (!(brick.buttonEnter.wasPressed())) {
brick.showValue("min", min, 4)
brick.showValue("max", v, 5)
brick.showValue("setpoint", setpoint, 6)
loops.pause(100)
pause(100)
}
loops.forever(function () {
forever(function () {
brick.clearScreen()
v = sensors.color3.light(LightIntensityMode.Reflected)
brick.showValue("light", v, 1)

View File

@ -15,7 +15,7 @@ The blocks in MakeCode have similar functions and go together in the same way: t
```blocks
motors.largeA.setSpeed(50)
loops.pause(1000)
pause(1000)
motors.largeA.stop()
```
@ -23,7 +23,7 @@ Any block program can be converted to JavaScript and you can edit it as lines of
```typescript
motors.largeA.setSpeed(50)
loops.pause(1000)
pause(1000)
motors.largeA.stop()
```
@ -133,7 +133,7 @@ It is quite common to have to wait for a task to finish or for a sensor state to
```blocks
motors.largeD.setSpeed(50)
loops.pause(1000)
pause(1000)
motors.largeD.stop();
```
@ -166,7 +166,7 @@ motors.largeD.stop()
![Single loop](/static/labview/loopinfinite.png)
```blocks
loops.forever(() => {
forever(() => {
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
})
@ -193,7 +193,7 @@ while(k < 10) {
```blocks
let light = 0;
loops.forever(function () {
forever(function () {
light = sensors.color3.light(LightIntensityMode.Reflected);
motors.largeD.setSpeed(light)
})
@ -206,15 +206,15 @@ You can start up multiple ``||loops:forever||`` loops that will run at the same
![Multiple loops running at the same time](/static/labview/multipleloops.png)
```blocks
loops.forever(() => {
forever(() => {
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
})
loops.forever(() => {
forever(() => {
brick.showImage(images.eyesMiddleRight)
loops.pause(1000)
pause(1000)
brick.showImage(images.eyesMiddleLeft)
loops.pause(1000)
pause(1000)
})
```
@ -225,7 +225,7 @@ The ``||logic:if||`` block allows you to run different code depending on whether
![Brake block](/static/labview/ife.png)
```blocks
loops.forever(function() {
forever(function() {
if(sensors.touch1.isPressed()) {
motors.largeD.setSpeed(50)
} else {
@ -241,8 +241,8 @@ The ``||math:pick random||`` block returns a random number selected from a range
![Brake block](/static/labview/random.png)
```blocks
loops.forever(function () {
forever(function () {
motors.largeBC.steer(Math.randomRange(-5, 5), 50)
loops.pause(100)
pause(100)
})
```

View File

@ -3,13 +3,13 @@
Use this program with the Programmable Brick and Large Motor.
```blocks
loops.forever(function () {
forever(function () {
motors.largeA.setSpeed(30)
loops.pause(100)
pause(100)
motors.largeA.stop()
music.playSoundEffectUntilDone(sounds.animalsCatPurr)
motors.largeA.setSpeed(-30)
loops.pause(100)
pause(100)
motors.largeA.stop()
})
```

View File

@ -3,10 +3,10 @@
This example program combined with the small model will make a beat and rhythm on any surface when the program is run.
```blocks
loops.forever(function () {
forever(function () {
motors.largeA.setSpeed(50)
loops.pause(200)
pause(200)
motors.largeA.setSpeed(100)
loops.pause(200)
pause(200)
})
```

View File

@ -16,7 +16,7 @@ Show the battery level percentage on the screen. Also, show a green light if the
```blocks
let battery = 0;
loops.forever(function() {
forever(function() {
brick.showString("Battery level:", 1)
brick.showNumber(battery, 2)
battery = brick.batteryLevel();
@ -28,6 +28,6 @@ loops.forever(function() {
} else {
brick.setStatusLight(StatusLight.RedPulse)
}
loops.pause(30000)
pause(30000)
})
```

View File

@ -32,7 +32,7 @@ Set the brick light to green when the `down` is pressed. When the button is not
```blocks
let isRed = false;
loops.forever(function() {
forever(function() {
if (brick.buttonLeft.isPressed()) {
brick.setStatusLight(StatusLight.Green);
isRed = false;

View File

@ -16,7 +16,7 @@ brick.showString("self-destruct in:", 2);
brick.showString("seconds", 5);
for (let i = 0; i < 10; i++) {
brick.showNumber(10 - i, 4);
loops.pause(1000);
pause(1000);
}
brick.clearScreen();
```

View File

@ -24,14 +24,14 @@ brick.setStatusLight(StatusLight.Red);
Repeatedly show a different color pattern for the brick light.
```blocks
loops.forever(function () {
forever(function () {
brick.setStatusLight(StatusLight.Orange)
loops.pause(1000)
pause(1000)
brick.setStatusLight(StatusLight.GreenFlash)
loops.pause(2000)
pause(2000)
brick.setStatusLight(StatusLight.RedPulse)
loops.pause(2000)
pause(2000)
brick.setStatusLight(StatusLight.Off)
loops.pause(500)
pause(500)
})
```

View File

@ -20,7 +20,7 @@ Reset the motor connected to port **A** and run it for for 2 seconds at a speed
let motorAngle = 0;
motors.largeA.reset()
motors.largeA.setSpeed(45)
loops.pause(2000)
pause(2000)
motors.largeA.stop()
motorAngle = motors.largeA.angle()
```

View File

@ -16,11 +16,11 @@ See if the motor turns the same number of times for each of two count periods. R
let tachoCount = 0;
motors.largeA.reset()
motors.largeA.setSpeed(50)
loops.pause(10000)
pause(10000)
tachoCount = motors.largeA.tacho()
motors.largeA.clearCounts()
motors.largeA.setSpeed(50)
loops.pause(10000)
pause(10000)
if (tachoCount == motors.largeA.tacho()) {
brick.showString("Motor turns equal.", 1)
} else {

View File

@ -14,12 +14,12 @@ See what the angle count is when a motor is stopped. Then, try it again after a
```blocks
motors.largeA.setSpeed(30)
loops.pause(2000)
pause(2000)
motors.largeA.stop()
brick.showString("Angle count:", 1)
brick.showNumber(motors.largeA.angle(), 2)
motors.largeA.setSpeed(30)
loops.pause(2000)
pause(2000)
motors.largeA.reset()
brick.showString("Angle count:", 4)
brick.showNumber(motors.largeA.angle(), 5)

View File

@ -20,7 +20,7 @@ Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and
```blocks
motors.largeA.setSpeed(30)
loops.pause(2000)
pause(2000)
motors.largeA.stop()
motors.largeA.setBrake(true)
```

View File

@ -18,12 +18,12 @@ Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and
```blocks
motors.largeA.setSpeed(30)
loops.pause(2000)
pause(2000)
motors.largeA.stop()
loops.pause(2000)
pause(2000)
motors.largeA.setInverted(true)
motors.largeA.setSpeed(-30)
loops.pause(2000)
pause(2000)
motors.largeA.stop()
```

View File

@ -23,7 +23,7 @@ Turn off the speed regulation for the motor connected to port **A**.
```blocks
motors.largeA.setRegulated(false)
motors.largeA.setSpeed(75)
loops.pause(20000)
pause(20000)
motors.largeA.stop()
```

View File

@ -69,7 +69,7 @@ Run the motor connected to port **A** continuously. Pause 20 seconds and then st
```blocks
motors.largeA.setSpeed(75)
loops.pause(20000)
pause(20000)
motors.largeA.stop()
```
@ -79,7 +79,7 @@ Run the motor connected to port **A** in reverse. Pause 5 seconds and then stop
```blocks
motors.largeA.setSpeed(-60)
loops.pause(5000)
pause(5000)
motors.largeA.stop()
```

View File

@ -21,7 +21,7 @@ motors.largeA.setRegulated(false)
motors.largeA.setSpeed(55)
brick.showString("Actual speed:", 1)
for (let i = 0; i < 30; i++) {
loops.pause(500)
pause(500)
brick.showNumber(motors.largeA.speed(), 3)
}
motors.largeA.stop()

View File

@ -14,9 +14,9 @@ Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and
```blocks
motors.largeA.setSpeed(30)
loops.pause(2000)
pause(2000)
motors.largeA.stop()
loops.pause(2000)
pause(2000)
motors.largeA.setSpeed(50)
```

View File

@ -34,7 +34,7 @@ Run the motor connected to port **A** at half speed for 5 seconds. Display the n
```blocks
motors.largeA.setSpeed(50)
loops.pause(5000)
pause(5000)
motors.largeA.stop()
brick.showString("Motor rotations:", 1)
brick.showNumber(motors.largeA.tacho() / 360, 3)

View File

@ -14,7 +14,7 @@ Tank the @boardname@ forward at half speed for 5 seconds and then stop.
```blocks
motors.largeAB.tank(50, 50);
loops.pause(5000);
pause(5000);
motors.stopAll();
```

View File

@ -72,9 +72,9 @@ Steer the brick in a snake pattern for a short time.
```block
for (let i = 0; i < 4; i++) {
motors.largeBC.steer(30, 30)
loops.pause(5000)
pause(5000)
motors.largeBC.steer(-30, 30)
loops.pause(5000)
pause(5000)
}
motors.stopAll()
```

View File

@ -43,9 +43,9 @@ Move the brick straight ahead and then go backward.
```blocks
motors.largeAB.tank(75, 75)
loops.pause(10000)
pause(10000)
motors.largeAB.tank(-55, -55)
loops.pause(10000)
pause(10000)
motors.stopAll()
```
@ -72,7 +72,7 @@ Run both motors in opposite directions to spin the brick around to the left.
```blocks
motors.largeAB.tank(-30, 30)
loops.pause(5000)
pause(5000)
motors.stopAll()
```

View File

@ -70,17 +70,17 @@ declare namespace loops {
* Repeats the code forever in the background. On each iteration, allows other codes to run.
* @param body code to execute
*/
//% help=loops/forever weight=100 afterOnStart=true
//% blockId=forever block="forever" blockAllowMultiple=1 shim=loops::forever
//% help=loops/forever weight=100 afterOnStart=true deprecated=true
//% blockId=forever_deprecated block="forever" blockAllowMultiple=1 shim=loops::forever
function forever(a: () => void): void;
/**
* Pause for the specified time in milliseconds
* @param ms how long to pause for, eg: 100, 200, 500, 1000, 2000
*/
//% help=loops/pause weight=99
//% help=loops/pause weight=99 deprecated=true
//% async block="pause %pause=timePicker|ms"
//% blockId=device_pause shim=loops::pause
//% blockId=device_pause_deprecated shim=loops::pause
function pause(ms: int32): void;
}
declare namespace control {

View File

@ -294,7 +294,7 @@ namespace sensors {
}
// wait a bit
loops.pause(50);
pause(50);
}
// apply tolerance

View File

@ -1,7 +1,7 @@
# Ambient Light
```blocks
loops.forever(function () {
forever(function () {
if (sensors.color1.ambientLight() > 20) {
brick.setStatusLight(StatusLight.Green)
} else {

View File

@ -1,7 +1,7 @@
# color
```blocks
loops.forever(function () {
forever(function () {
if (sensors.color1.color() == ColorSensorColor.Green) {
brick.setStatusLight(StatusLight.Green)
} else {

View File

@ -1,7 +1,7 @@
# Reflected Light
```blocks
loops.forever(function () {
forever(function () {
if (sensors.color1.reflectedLight() > 20) {
brick.setStatusLight(StatusLight.Green)
} else {

View File

@ -15,7 +15,7 @@ namespace sensors.internal {
let prev = query()
changeHandler(prev, prev)
while (true) {
loops.pause(periodMs)
pause(periodMs)
let curr = query()
if (prev !== curr) {
changeHandler(prev, curr)
@ -57,9 +57,9 @@ namespace sensors.internal {
uartMM = control.mmap("/dev/lms_uart", UartOff.Size, 0)
if (!uartMM) control.fail("no uart sensor")
loops.forever(() => {
forever(() => {
detectDevices()
loops.pause(500)
pause(500)
})
for (let info_ of sensorInfos) {
@ -258,7 +258,7 @@ namespace sensors.internal {
if (port < 0) return 0
let s = getUartStatus(port)
if (s) return s
loops.pause(25)
pause(25)
}
}
@ -280,7 +280,7 @@ namespace sensors.internal {
uartMM.setNumber(NumberFormat.Int8LE, UartOff.Status + port,
getUartStatus(port) & 0xfffe)
loops.pause(10)
pause(10)
}
}
@ -299,7 +299,7 @@ namespace sensors.internal {
} else {
break
}
loops.pause(10)
pause(10)
}
}

View File

@ -202,7 +202,7 @@ namespace motors {
// if we've recently completed a motor command with brake
// allow 500ms for robot to settle
if(this._brake)
loops.pause(500);
pause(500);
}
/**

View File

@ -31,15 +31,15 @@ brick.buttonUp.onEvent(ButtonEvent.Bumped, () => {
let num = 0
loops.forever(() => {
forever(() => {
serial.writeDmesg()
loops.pause(100)
pause(100)
})
/*
loops.forever(() => {
forever(() => {
let v = input.color.getColor()
screen.print(10, 60, v + " ")
loops.pause(200)
pause(200)
})
*/

View File

@ -41,7 +41,7 @@ namespace control {
//% blockId=timerPauseUntil block="%timer|pause until (ms) %ms"
pauseUntil(ms: number) {
const remaining = this.millis() - ms;
loops.pause(Math.max(0, remaining));
pause(Math.max(0, remaining));
}
}

View File

@ -1,4 +1,4 @@
// This is the last thing executed before user code
// We pause for 100ms to give time to read sensor values, so they work in on_start block
loops.pause(100)
pause(100)

View File

@ -18,7 +18,7 @@ When the brick is in motion, it moves in the direction of one of axes used to me
Flash the status light to red if the roll rate of `gyro 2` is more that `30` degrees per second.
```blocks
loops.forever(function () {
forever(function () {
if (sensors.gyro2.rate() > 30) {
brick.setStatusLight(StatusLight.RedFlash)
} else {

View File

@ -95,7 +95,7 @@ namespace sensors {
this.calibrating = true;
// may be triggered by a button click,
// give time for robot to settle
loops.pause(700);
pause(700);
// send a reset command
super.reset();
// switch back to the desired mode
@ -103,13 +103,13 @@ namespace sensors {
// wait till sensor is live
pauseUntil(() => this.isActive());
// give it a bit of time to init
loops.pause(1000)
pause(1000)
// compute drift
this._drift = 0;
if (this.mode == GyroSensorMode.Rate) {
for (let i = 0; i < 200; ++i) {
this._drift += this._query();
loops.pause(4);
pause(4);
}
this._drift /= 200;
}

View File

@ -33,7 +33,7 @@ namespace brick {
brick.setStatusLight(this.light);
brick.showImage(this.image);
music.playSoundEffectUntilDone(this.sound);
loops.pause(20);
pause(20);
}
}

View File

@ -1,7 +1,7 @@
music.setVolume(3)
music.playTone(440, 500)
loops.pause(500)
pause(500)
music.playTone(1440, 500)
loops.pause(500)
pause(500)
music.playTone(2440, 500)
loops.pause(500)
pause(500)

View File

@ -9,7 +9,7 @@ Tests are registered as event handlers. They will automatically run once ``on st
```blocks
tests.test("lgB set speed 10", () => {
motors.largeB.setSpeed(10);
loops.pause(100)
pause(100)
tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
});
```

View File

@ -14,7 +14,7 @@ sensors.touch1.isPressed()
If the touch sensor ``touch 1`` is pressed, show a `green` status light. Otherwise, set the status light to `orange`.
```blocks
loops.forever(function () {
forever(function () {
if (sensors.touch1.isPressed()) {
brick.setStatusLight(StatusLight.Green)
} else {

View File

@ -17,13 +17,13 @@ If a touch sensor was pressed, then that event is remembered. Once you check if
If the touch sensor ``touch 1`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`.
```blocks
loops.forever(function () {
forever(function () {
if (sensors.touch1.wasPressed()) {
brick.setStatusLight(StatusLight.Green)
} else {
brick.setStatusLight(StatusLight.Orange)
}
loops.pause(500)
pause(500)
})
```

View File

@ -15,7 +15,7 @@ tests.test("Bright ambient light", function () {
let actualLight: number
for (let i = 0; i < 4; i++) {
actualLight = sensors.color1.ambientLight()
loops.pause(500)
pause(500)
}
tests.assertClose("Light", actualLight, 20, 15)
})
@ -29,7 +29,7 @@ tests.test("Bright reflected light", function () {
let actualLight: number
for (let i = 0; i < 4; i++) {
actualLight = sensors.color1.reflectedLight()
loops.pause(500)
pause(500)
}
tests.assertClose("Light", actualLight, 17, 14)
})

View File

@ -1,42 +1,42 @@
// add tests package
tests.test("lgB set speed 10", () => {
motors.largeB.setSpeed(10);
loops.pause(500)
pause(500)
tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
});
tests.test("lgB set speed 25 (reversed)", () => {
motors.largeB.setInverted(true)
motors.largeB.setSpeed(25)
loops.pause(500)
pause(500)
tests.assertClose("speedB", -25, motors.largeB.speed(), 2)
});
tests.test("lgBC set speed 5", () => {
motors.largeBC.setSpeed(5)
loops.pause(500)
pause(500)
tests.assertClose("speedB", 5, motors.largeB.speed(), 1);
tests.assertClose("speedC", 5, motors.largeC.speed(), 1);
});
tests.test("lgBC steer 50% 2x", () => {
motors.largeBC.setBrake(true)
motors.largeBC.steer(50, 50, 1, MoveUnit.Rotations)
loops.pause(2000)
pause(2000)
tests.assertClose("largeB", 360, motors.largeB.angle(), 5)
motors.largeBC.setBrake(false)
})
tests.test("lgBC steer 360deg", () => {
motors.largeBC.setBrake(true)
motors.largeBC.steer(50, 50, 360, MoveUnit.Degrees)
loops.pause(2000)
pause(2000)
tests.assertClose("largeB", 360, motors.largeB.angle(), 5)
});
tests.test("lgBC steer 50% 1s", () => {
motors.largeBC.setBrake(true)
motors.largeBC.steer(10, 50, 1000, MoveUnit.MilliSeconds)
loops.pause(2000)
pause(2000)
})
tests.test("lgBC tank 50% 180deg", () => {
motors.largeBC.setBrake(true)
motors.largeBC.tank(50, 50, 180, MoveUnit.Degrees)
loops.pause(1000)
pause(1000)
tests.assertClose("largeB", 180, motors.largeB.angle(), 5)
});