replacing loops.pause -> pause, loops.forever -> forever
This commit is contained in:
parent
0384eb4d9d
commit
daa88b299d
@ -3,6 +3,6 @@
|
|||||||
### #specific
|
### #specific
|
||||||
|
|
||||||
```cards
|
```cards
|
||||||
loops.forever(() => {});
|
forever(() => {});
|
||||||
loops.pause(0)
|
pause(0)
|
||||||
```
|
```
|
@ -7,6 +7,6 @@ while (true) {
|
|||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||||
}
|
}
|
||||||
loops.pause(1);
|
pause(1);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -8,6 +8,6 @@ while (true) {
|
|||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||||
}
|
}
|
||||||
loops.pause(1);
|
pause(1);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
```blocks
|
```blocks
|
||||||
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
|
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
|
||||||
brick.showImage(images.objectsLightOn)
|
brick.showImage(images.objectsLightOn)
|
||||||
loops.pause(5000)
|
pause(5000)
|
||||||
brick.clearScreen()
|
brick.clearScreen()
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -1,9 +1,9 @@
|
|||||||
# Reverse Beeper Activity 1
|
# Reverse Beeper Activity 1
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
music.playTone(440, sensors.ultrasonic4.distance());
|
music.playTone(440, sensors.ultrasonic4.distance());
|
||||||
loops.pause(50)
|
pause(50)
|
||||||
})
|
})
|
||||||
motors.largeBC.setSpeed(-20);
|
motors.largeBC.setSpeed(-20);
|
||||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
# Reverse Beeper Activity 2
|
# Reverse Beeper Activity 2
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
if (motors.largeB.speed() != 0 && sensors.ultrasonic4.distance() < 20) {
|
if (motors.largeB.speed() != 0 && sensors.ultrasonic4.distance() < 20) {
|
||||||
music.playTone(440, sensors.ultrasonic4.distance());
|
music.playTone(440, sensors.ultrasonic4.distance());
|
||||||
loops.pause(50)
|
pause(50)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
motors.largeBC.setSpeed(-20);
|
motors.largeBC.setSpeed(-20);
|
||||||
|
@ -13,7 +13,7 @@ control.runInParallel(function () {
|
|||||||
while (beep) {
|
while (beep) {
|
||||||
if (sensors.ultrasonic4.distance() < 20) {
|
if (sensors.ultrasonic4.distance() < 20) {
|
||||||
music.playTone(440, sensors.ultrasonic4.distance())
|
music.playTone(440, sensors.ultrasonic4.distance())
|
||||||
loops.pause(50)
|
pause(50)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -5,10 +5,10 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
|||||||
motors.largeBC.setSpeed(50)
|
motors.largeBC.setSpeed(50)
|
||||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||||
motors.largeBC.setSpeed(0)
|
motors.largeBC.setSpeed(0)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||||
motors.largeBC.setSpeed(-50)
|
motors.largeBC.setSpeed(-50)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeBC.setSpeed(0)
|
motors.largeBC.setSpeed(0)
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -6,10 +6,10 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
|||||||
motors.largeBC.setSpeed(50)
|
motors.largeBC.setSpeed(50)
|
||||||
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
||||||
motors.largeBC.setSpeed(0)
|
motors.largeBC.setSpeed(0)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||||
motors.largeBC.setSpeed(-50)
|
motors.largeBC.setSpeed(-50)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeBC.setSpeed(0)
|
motors.largeBC.setSpeed(0)
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -9,11 +9,11 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
|||||||
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
||||||
brick.showImage(images.eyesTiredMiddle)
|
brick.showImage(images.eyesTiredMiddle)
|
||||||
motors.largeBC.setSpeed(0)
|
motors.largeBC.setSpeed(0)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||||
brick.showImage(images.eyesDizzy)
|
brick.showImage(images.eyesDizzy)
|
||||||
motors.largeBC.setSpeed(-50)
|
motors.largeBC.setSpeed(-50)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeBC.setSpeed(0)
|
motors.largeBC.setSpeed(0)
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -15,7 +15,7 @@ brick.buttonDown.onEvent(ButtonEvent.Bumped, function () {
|
|||||||
drive.push(5)
|
drive.push(5)
|
||||||
})
|
})
|
||||||
pauseUntil(() => drive.length >= 5)
|
pauseUntil(() => drive.length >= 5)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
music.playSoundEffectUntilDone(sounds.communicationGo)
|
music.playSoundEffectUntilDone(sounds.communicationGo)
|
||||||
for (let d of drive) {
|
for (let d of drive) {
|
||||||
if (d == 1) {
|
if (d == 1) {
|
||||||
|
@ -19,7 +19,7 @@ brick.buttonDown.onEvent(ButtonEvent.Bumped, function () {
|
|||||||
music.playSoundEffectUntilDone(sounds.systemClick)
|
music.playSoundEffectUntilDone(sounds.systemClick)
|
||||||
})
|
})
|
||||||
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped);
|
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped);
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
music.playSoundEffectUntilDone(sounds.communicationGo)
|
music.playSoundEffectUntilDone(sounds.communicationGo)
|
||||||
for (let d of drive) {
|
for (let d of drive) {
|
||||||
if (d == 1) {
|
if (d == 1) {
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
```blocks
|
```blocks
|
||||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||||
motors.largeBC.tank(75, 30)
|
motors.largeBC.tank(75, 30)
|
||||||
loops.pause(1500)
|
pause(1500)
|
||||||
motors.largeBC.tank(-30, -75)
|
motors.largeBC.tank(-30, -75)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
motors.largeBC.tank(50, 50)
|
motors.largeBC.tank(50, 50)
|
||||||
loops.pause(3000)
|
pause(3000)
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -3,12 +3,12 @@
|
|||||||
```blocks
|
```blocks
|
||||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||||
motors.largeBC.tank(75, 30)
|
motors.largeBC.tank(75, 30)
|
||||||
loops.pause(1500)
|
pause(1500)
|
||||||
motors.largeBC.tank(-30, -75)
|
motors.largeBC.tank(-30, -75)
|
||||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
||||||
motors.largeBC.tank(0, 0)
|
motors.largeBC.tank(0, 0)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
motors.largeBC.tank(50, 50)
|
motors.largeBC.tank(50, 50)
|
||||||
loops.pause(3000)
|
pause(3000)
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -3,13 +3,13 @@
|
|||||||
```blocks
|
```blocks
|
||||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||||
motors.largeBC.tank(75, 30)
|
motors.largeBC.tank(75, 30)
|
||||||
loops.pause(1500)
|
pause(1500)
|
||||||
motors.largeBC.tank(-30, -75)
|
motors.largeBC.tank(-30, -75)
|
||||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
||||||
motors.largeBC.tank(0, 0)
|
motors.largeBC.tank(0, 0)
|
||||||
music.playSoundEffect(sounds.animalsDogBark1)
|
music.playSoundEffect(sounds.animalsDogBark1)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
motors.largeBC.tank(50, 50)
|
motors.largeBC.tank(50, 50)
|
||||||
loops.pause(3000)
|
pause(3000)
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -1,7 +1,7 @@
|
|||||||
# Traffic Lights Activity 3
|
# Traffic Lights Activity 3
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
if (sensors.color3.light(LightIntensityMode.Reflected) < 15) {
|
if (sensors.color3.light(LightIntensityMode.Reflected) < 15) {
|
||||||
motors.largeBC.tank(30, 12)
|
motors.largeBC.tank(30, 12)
|
||||||
} else {
|
} else {
|
||||||
|
@ -127,7 +127,7 @@ sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
|
|||||||
} else {
|
} else {
|
||||||
controlSteering = -70
|
controlSteering = -70
|
||||||
}
|
}
|
||||||
loops.pause(4000)
|
pause(4000)
|
||||||
music.playTone(2000, 100)
|
music.playTone(2000, 100)
|
||||||
controlSteering = 0
|
controlSteering = 0
|
||||||
controlDrive = oldControlDrive
|
controlDrive = oldControlDrive
|
||||||
@ -162,7 +162,7 @@ sensors.color1.onColorDetected(ColorSensorColor.White, function () {
|
|||||||
})
|
})
|
||||||
timestep = 0.014
|
timestep = 0.014
|
||||||
// main loop
|
// main loop
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
reset()
|
reset()
|
||||||
while (!fallen) {
|
while (!fallen) {
|
||||||
control.timer3.pauseUntil(5)
|
control.timer3.pauseUntil(5)
|
||||||
|
@ -36,7 +36,7 @@ function RST() {
|
|||||||
sensors.gyro2.reset()
|
sensors.gyro2.reset()
|
||||||
sensors.gyro2.rate()
|
sensors.gyro2.rate()
|
||||||
control.timer2.reset()
|
control.timer2.reset()
|
||||||
loops.pause(5000)
|
pause(5000)
|
||||||
mSum = 0;
|
mSum = 0;
|
||||||
mPos = 0;
|
mPos = 0;
|
||||||
mD = 0;
|
mD = 0;
|
||||||
@ -65,7 +65,7 @@ function OS() {
|
|||||||
gSum = gyro;
|
gSum = gyro;
|
||||||
gMx = Math.max(gMx, gyro)
|
gMx = Math.max(gMx, gyro)
|
||||||
gMn = Math.min(gMn, gyro)
|
gMn = Math.min(gMn, gyro)
|
||||||
loops.pause(4);
|
pause(4);
|
||||||
}
|
}
|
||||||
} while (gMx - gMn > 2);
|
} while (gMx - gMn > 2);
|
||||||
gOS = gSum / 200;
|
gOS = gSum / 200;
|
||||||
@ -121,7 +121,7 @@ function CHK() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// M
|
// M
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
RST();
|
RST();
|
||||||
brick.showImage(images.eyesSleeping)
|
brick.showImage(images.eyesSleeping)
|
||||||
OS()
|
OS()
|
||||||
@ -142,7 +142,7 @@ loops.forever(function () {
|
|||||||
CHK()
|
CHK()
|
||||||
let t2 = control.timer1.millis();
|
let t2 = control.timer1.millis();
|
||||||
let p = 5 - (t2 - t1);
|
let p = 5 - (t2 - t1);
|
||||||
loops.pause(Math.max(1, p))
|
pause(Math.max(1, p))
|
||||||
}
|
}
|
||||||
motors.stopAll()
|
motors.stopAll()
|
||||||
st = 0;
|
st = 0;
|
||||||
@ -154,7 +154,7 @@ loops.forever(function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// BHV
|
// BHV
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
switch (st) {
|
switch (st) {
|
||||||
case 0:
|
case 0:
|
||||||
Cdrv = 0;
|
Cdrv = 0;
|
||||||
@ -162,7 +162,7 @@ loops.forever(function () {
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Cdrv = 40;
|
Cdrv = 40;
|
||||||
loops.pause(4000);
|
pause(4000);
|
||||||
Cdrv = 0;
|
Cdrv = 0;
|
||||||
music.playTone(1000, 100);
|
music.playTone(1000, 100);
|
||||||
st = 2;
|
st = 2;
|
||||||
@ -203,13 +203,13 @@ loops.forever(function () {
|
|||||||
Cstr = 70;
|
Cstr = 70;
|
||||||
else
|
else
|
||||||
Cstr = -70;
|
Cstr = -70;
|
||||||
loops.pause(4000);
|
pause(4000);
|
||||||
music.playTone(2000, 100)
|
music.playTone(2000, 100)
|
||||||
Cstr = 0;
|
Cstr = 0;
|
||||||
Cdrv = oldDr;
|
Cdrv = oldDr;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
loops.pause(80);
|
pause(80);
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -21,7 +21,7 @@ let GTO = 0;
|
|||||||
function DN() {
|
function DN() {
|
||||||
motors.largeAD.setBrake(true);
|
motors.largeAD.setBrake(true);
|
||||||
motors.largeAD.tank(50, 50, 1, MoveUnit.Seconds);
|
motors.largeAD.tank(50, 50, 1, MoveUnit.Seconds);
|
||||||
loops.pause(100);
|
pause(100);
|
||||||
motors.largeA.clearCounts()
|
motors.largeA.clearCounts()
|
||||||
motors.largeD.clearCounts()
|
motors.largeD.clearCounts()
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ function UP() {
|
|||||||
pauseUntil(() => motors.largeA.angle() < -65);
|
pauseUntil(() => motors.largeA.angle() < -65);
|
||||||
motors.largeA.stop();
|
motors.largeA.stop();
|
||||||
|
|
||||||
loops.pause(500);
|
pause(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,7 +277,7 @@ function NGR() {
|
|||||||
IS(4)
|
IS(4)
|
||||||
music.playSoundEffect(sounds.animalsDogGrowl);
|
music.playSoundEffect(sounds.animalsDogGrowl);
|
||||||
UP();
|
UP();
|
||||||
loops.pause(1500);
|
pause(1500);
|
||||||
music.stopAllSounds()
|
music.stopAllSounds()
|
||||||
music.playSoundEffect(sounds.animalsDogBark1)
|
music.playSoundEffect(sounds.animalsDogBark1)
|
||||||
P_C--;
|
P_C--;
|
||||||
@ -303,11 +303,11 @@ function PPP() {
|
|||||||
NS = false;
|
NS = false;
|
||||||
IS(2);
|
IS(2);
|
||||||
UP();
|
UP();
|
||||||
loops.pause(100)
|
pause(100)
|
||||||
motors.largeA.setSpeed(-30, 70, MoveUnit.Degrees);
|
motors.largeA.setSpeed(-30, 70, MoveUnit.Degrees);
|
||||||
loops.pause(800);
|
pause(800);
|
||||||
music.playSoundEffect(sounds.mechanicalHorn1);
|
music.playSoundEffect(sounds.mechanicalHorn1);
|
||||||
loops.pause(1000);
|
pause(1000);
|
||||||
for(let i = 0; i < 3; ++i) {
|
for(let i = 0; i < 3; ++i) {
|
||||||
motors.largeA.setSpeed(-30, 20, MoveUnit.Degrees);
|
motors.largeA.setSpeed(-30, 20, MoveUnit.Degrees);
|
||||||
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) {
|
for(let i = 0; i < 3; ++i) {
|
||||||
music.playSoundEffect(sounds.animalsDogBark1);
|
music.playSoundEffect(sounds.animalsDogBark1);
|
||||||
motors.largeAD.setSpeed(-100, 0.2, MoveUnit.Seconds);
|
motors.largeAD.setSpeed(-100, 0.2, MoveUnit.Seconds);
|
||||||
loops.pause(300)
|
pause(300)
|
||||||
motors.largeAD.setSpeed(10, 0.3, MoveUnit.Seconds)
|
motors.largeAD.setSpeed(10, 0.3, MoveUnit.Seconds)
|
||||||
}
|
}
|
||||||
loops.pause(500);
|
pause(500);
|
||||||
music.stopAllSounds();
|
music.stopAllSounds();
|
||||||
DN();
|
DN();
|
||||||
RST();
|
RST();
|
||||||
@ -347,7 +347,7 @@ function WKU() {
|
|||||||
MHT(0)
|
MHT(0)
|
||||||
DN()
|
DN()
|
||||||
STL()
|
STL()
|
||||||
loops.pause(1000);
|
pause(1000);
|
||||||
UP()
|
UP()
|
||||||
CS(0;)
|
CS(0;)
|
||||||
}
|
}
|
||||||
@ -358,7 +358,7 @@ MNRH();
|
|||||||
IS(1);
|
IS(1);
|
||||||
UP();
|
UP();
|
||||||
RST();
|
RST();
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
MON();
|
MON();
|
||||||
switch (DB_S) {
|
switch (DB_S) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -18,7 +18,7 @@ function INI() {
|
|||||||
INI()
|
INI()
|
||||||
|
|
||||||
let down = false;
|
let down = false;
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
brick.showImage(images.informationQuestionMark)
|
brick.showImage(images.informationQuestionMark)
|
||||||
brick.setStatusLight(StatusLight.OrangePulse);
|
brick.setStatusLight(StatusLight.OrangePulse);
|
||||||
pauseUntil(() => (down = brick.buttonDown.wasPressed()) || brick.buttonUp.wasPressed())
|
pauseUntil(() => (down = brick.buttonDown.wasPressed()) || brick.buttonUp.wasPressed())
|
||||||
|
@ -18,7 +18,7 @@ function INI() {
|
|||||||
INI()
|
INI()
|
||||||
|
|
||||||
let down = false;
|
let down = false;
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
brick.showImage(images.informationQuestionMark)
|
brick.showImage(images.informationQuestionMark)
|
||||||
brick.setStatusLight(StatusLight.OrangePulse);
|
brick.setStatusLight(StatusLight.OrangePulse);
|
||||||
pauseUntil(() => (down = brick.buttonDown.wasPressed()) || brick.buttonUp.wasPressed())
|
pauseUntil(() => (down = brick.buttonDown.wasPressed()) || brick.buttonUp.wasPressed())
|
||||||
|
@ -36,7 +36,7 @@ function RST() {
|
|||||||
sensors.gyro2.reset()
|
sensors.gyro2.reset()
|
||||||
sensors.gyro2.rate()
|
sensors.gyro2.rate()
|
||||||
control.timer2.reset()
|
control.timer2.reset()
|
||||||
loops.pause(5000)
|
pause(5000)
|
||||||
mSum = 0;
|
mSum = 0;
|
||||||
mPos = 0;
|
mPos = 0;
|
||||||
mD = 0;
|
mD = 0;
|
||||||
@ -65,7 +65,7 @@ function OS() {
|
|||||||
gSum = gyro;
|
gSum = gyro;
|
||||||
gMx = Math.max(gMx, gyro)
|
gMx = Math.max(gMx, gyro)
|
||||||
gMn = Math.min(gMn, gyro)
|
gMn = Math.min(gMn, gyro)
|
||||||
loops.pause(4);
|
pause(4);
|
||||||
}
|
}
|
||||||
} while (gMx - gMn > 2);
|
} while (gMx - gMn > 2);
|
||||||
gOS = gSum / 200;
|
gOS = gSum / 200;
|
||||||
@ -121,7 +121,7 @@ function CHK() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// M
|
// M
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
RST();
|
RST();
|
||||||
brick.showImage(images.eyesSleeping)
|
brick.showImage(images.eyesSleeping)
|
||||||
OS()
|
OS()
|
||||||
@ -142,7 +142,7 @@ loops.forever(function () {
|
|||||||
CHK()
|
CHK()
|
||||||
let t2 = control.timer1.millis();
|
let t2 = control.timer1.millis();
|
||||||
let p = 5 - (t2 - t1);
|
let p = 5 - (t2 - t1);
|
||||||
loops.pause(Math.max(1, p))
|
pause(Math.max(1, p))
|
||||||
}
|
}
|
||||||
motors.stopAll()
|
motors.stopAll()
|
||||||
st = 0;
|
st = 0;
|
||||||
@ -154,7 +154,7 @@ loops.forever(function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// BHV
|
// BHV
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
switch (st) {
|
switch (st) {
|
||||||
case 0:
|
case 0:
|
||||||
Cdrv = 0;
|
Cdrv = 0;
|
||||||
@ -162,7 +162,7 @@ loops.forever(function () {
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Cdrv = 40;
|
Cdrv = 40;
|
||||||
loops.pause(4000);
|
pause(4000);
|
||||||
Cdrv = 0;
|
Cdrv = 0;
|
||||||
music.playTone(1000, 100);
|
music.playTone(1000, 100);
|
||||||
st = 2;
|
st = 2;
|
||||||
@ -203,13 +203,13 @@ loops.forever(function () {
|
|||||||
Cstr = 70;
|
Cstr = 70;
|
||||||
else
|
else
|
||||||
Cstr = -70;
|
Cstr = -70;
|
||||||
loops.pause(4000);
|
pause(4000);
|
||||||
music.playTone(2000, 100)
|
music.playTone(2000, 100)
|
||||||
Cstr = 0;
|
Cstr = 0;
|
||||||
Cdrv = oldDr;
|
Cdrv = oldDr;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
loops.pause(80);
|
pause(80);
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -26,9 +26,9 @@ while (!(brick.buttonEnter.wasPressed())) {
|
|||||||
brick.showValue("min", min, 4)
|
brick.showValue("min", min, 4)
|
||||||
brick.showValue("max", v, 5)
|
brick.showValue("max", v, 5)
|
||||||
brick.showValue("setpoint", setpoint, 6)
|
brick.showValue("setpoint", setpoint, 6)
|
||||||
loops.pause(100)
|
pause(100)
|
||||||
}
|
}
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
brick.clearScreen()
|
brick.clearScreen()
|
||||||
v = sensors.color3.light(LightIntensityMode.Reflected)
|
v = sensors.color3.light(LightIntensityMode.Reflected)
|
||||||
brick.showValue("light", v, 1)
|
brick.showValue("light", v, 1)
|
||||||
|
@ -15,7 +15,7 @@ The blocks in MakeCode have similar functions and go together in the same way: t
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
motors.largeA.setSpeed(50)
|
motors.largeA.setSpeed(50)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ Any block program can be converted to JavaScript and you can edit it as lines of
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
motors.largeA.setSpeed(50)
|
motors.largeA.setSpeed(50)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
motors.largeA.stop()
|
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
|
```blocks
|
||||||
motors.largeD.setSpeed(50)
|
motors.largeD.setSpeed(50)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
motors.largeD.stop();
|
motors.largeD.stop();
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ motors.largeD.stop()
|
|||||||
![Single loop](/static/labview/loopinfinite.png)
|
![Single loop](/static/labview/loopinfinite.png)
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(() => {
|
forever(() => {
|
||||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||||
})
|
})
|
||||||
@ -193,7 +193,7 @@ while(k < 10) {
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let light = 0;
|
let light = 0;
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
light = sensors.color3.light(LightIntensityMode.Reflected);
|
light = sensors.color3.light(LightIntensityMode.Reflected);
|
||||||
motors.largeD.setSpeed(light)
|
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)
|
![Multiple loops running at the same time](/static/labview/multipleloops.png)
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(() => {
|
forever(() => {
|
||||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||||
})
|
})
|
||||||
loops.forever(() => {
|
forever(() => {
|
||||||
brick.showImage(images.eyesMiddleRight)
|
brick.showImage(images.eyesMiddleRight)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
brick.showImage(images.eyesMiddleLeft)
|
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)
|
![Brake block](/static/labview/ife.png)
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function() {
|
forever(function() {
|
||||||
if(sensors.touch1.isPressed()) {
|
if(sensors.touch1.isPressed()) {
|
||||||
motors.largeD.setSpeed(50)
|
motors.largeD.setSpeed(50)
|
||||||
} else {
|
} else {
|
||||||
@ -241,8 +241,8 @@ The ``||math:pick random||`` block returns a random number selected from a range
|
|||||||
![Brake block](/static/labview/random.png)
|
![Brake block](/static/labview/random.png)
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
motors.largeBC.steer(Math.randomRange(-5, 5), 50)
|
motors.largeBC.steer(Math.randomRange(-5, 5), 50)
|
||||||
loops.pause(100)
|
pause(100)
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -3,13 +3,13 @@
|
|||||||
Use this program with the Programmable Brick and Large Motor.
|
Use this program with the Programmable Brick and Large Motor.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
motors.largeA.setSpeed(30)
|
motors.largeA.setSpeed(30)
|
||||||
loops.pause(100)
|
pause(100)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
music.playSoundEffectUntilDone(sounds.animalsCatPurr)
|
music.playSoundEffectUntilDone(sounds.animalsCatPurr)
|
||||||
motors.largeA.setSpeed(-30)
|
motors.largeA.setSpeed(-30)
|
||||||
loops.pause(100)
|
pause(100)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
@ -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.
|
This example program combined with the small model will make a beat and rhythm on any surface when the program is run.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
motors.largeA.setSpeed(50)
|
motors.largeA.setSpeed(50)
|
||||||
loops.pause(200)
|
pause(200)
|
||||||
motors.largeA.setSpeed(100)
|
motors.largeA.setSpeed(100)
|
||||||
loops.pause(200)
|
pause(200)
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -16,7 +16,7 @@ Show the battery level percentage on the screen. Also, show a green light if the
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let battery = 0;
|
let battery = 0;
|
||||||
loops.forever(function() {
|
forever(function() {
|
||||||
brick.showString("Battery level:", 1)
|
brick.showString("Battery level:", 1)
|
||||||
brick.showNumber(battery, 2)
|
brick.showNumber(battery, 2)
|
||||||
battery = brick.batteryLevel();
|
battery = brick.batteryLevel();
|
||||||
@ -28,6 +28,6 @@ loops.forever(function() {
|
|||||||
} else {
|
} else {
|
||||||
brick.setStatusLight(StatusLight.RedPulse)
|
brick.setStatusLight(StatusLight.RedPulse)
|
||||||
}
|
}
|
||||||
loops.pause(30000)
|
pause(30000)
|
||||||
})
|
})
|
||||||
```
|
```
|
@ -32,7 +32,7 @@ Set the brick light to green when the `down` is pressed. When the button is not
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let isRed = false;
|
let isRed = false;
|
||||||
loops.forever(function() {
|
forever(function() {
|
||||||
if (brick.buttonLeft.isPressed()) {
|
if (brick.buttonLeft.isPressed()) {
|
||||||
brick.setStatusLight(StatusLight.Green);
|
brick.setStatusLight(StatusLight.Green);
|
||||||
isRed = false;
|
isRed = false;
|
||||||
|
@ -16,7 +16,7 @@ brick.showString("self-destruct in:", 2);
|
|||||||
brick.showString("seconds", 5);
|
brick.showString("seconds", 5);
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
brick.showNumber(10 - i, 4);
|
brick.showNumber(10 - i, 4);
|
||||||
loops.pause(1000);
|
pause(1000);
|
||||||
}
|
}
|
||||||
brick.clearScreen();
|
brick.clearScreen();
|
||||||
```
|
```
|
||||||
|
@ -24,14 +24,14 @@ brick.setStatusLight(StatusLight.Red);
|
|||||||
Repeatedly show a different color pattern for the brick light.
|
Repeatedly show a different color pattern for the brick light.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
brick.setStatusLight(StatusLight.Orange)
|
brick.setStatusLight(StatusLight.Orange)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
brick.setStatusLight(StatusLight.GreenFlash)
|
brick.setStatusLight(StatusLight.GreenFlash)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
brick.setStatusLight(StatusLight.RedPulse)
|
brick.setStatusLight(StatusLight.RedPulse)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
brick.setStatusLight(StatusLight.Off)
|
brick.setStatusLight(StatusLight.Off)
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
@ -20,7 +20,7 @@ Reset the motor connected to port **A** and run it for for 2 seconds at a speed
|
|||||||
let motorAngle = 0;
|
let motorAngle = 0;
|
||||||
motors.largeA.reset()
|
motors.largeA.reset()
|
||||||
motors.largeA.setSpeed(45)
|
motors.largeA.setSpeed(45)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
motorAngle = motors.largeA.angle()
|
motorAngle = motors.largeA.angle()
|
||||||
```
|
```
|
||||||
|
@ -16,11 +16,11 @@ See if the motor turns the same number of times for each of two count periods. R
|
|||||||
let tachoCount = 0;
|
let tachoCount = 0;
|
||||||
motors.largeA.reset()
|
motors.largeA.reset()
|
||||||
motors.largeA.setSpeed(50)
|
motors.largeA.setSpeed(50)
|
||||||
loops.pause(10000)
|
pause(10000)
|
||||||
tachoCount = motors.largeA.tacho()
|
tachoCount = motors.largeA.tacho()
|
||||||
motors.largeA.clearCounts()
|
motors.largeA.clearCounts()
|
||||||
motors.largeA.setSpeed(50)
|
motors.largeA.setSpeed(50)
|
||||||
loops.pause(10000)
|
pause(10000)
|
||||||
if (tachoCount == motors.largeA.tacho()) {
|
if (tachoCount == motors.largeA.tacho()) {
|
||||||
brick.showString("Motor turns equal.", 1)
|
brick.showString("Motor turns equal.", 1)
|
||||||
} else {
|
} else {
|
||||||
|
@ -14,12 +14,12 @@ See what the angle count is when a motor is stopped. Then, try it again after a
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
motors.largeA.setSpeed(30)
|
motors.largeA.setSpeed(30)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
brick.showString("Angle count:", 1)
|
brick.showString("Angle count:", 1)
|
||||||
brick.showNumber(motors.largeA.angle(), 2)
|
brick.showNumber(motors.largeA.angle(), 2)
|
||||||
motors.largeA.setSpeed(30)
|
motors.largeA.setSpeed(30)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeA.reset()
|
motors.largeA.reset()
|
||||||
brick.showString("Angle count:", 4)
|
brick.showString("Angle count:", 4)
|
||||||
brick.showNumber(motors.largeA.angle(), 5)
|
brick.showNumber(motors.largeA.angle(), 5)
|
||||||
|
@ -20,7 +20,7 @@ Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
motors.largeA.setSpeed(30)
|
motors.largeA.setSpeed(30)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
motors.largeA.setBrake(true)
|
motors.largeA.setBrake(true)
|
||||||
```
|
```
|
||||||
|
@ -18,12 +18,12 @@ Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
motors.largeA.setSpeed(30)
|
motors.largeA.setSpeed(30)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeA.setInverted(true)
|
motors.largeA.setInverted(true)
|
||||||
motors.largeA.setSpeed(-30)
|
motors.largeA.setSpeed(-30)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ Turn off the speed regulation for the motor connected to port **A**.
|
|||||||
```blocks
|
```blocks
|
||||||
motors.largeA.setRegulated(false)
|
motors.largeA.setRegulated(false)
|
||||||
motors.largeA.setSpeed(75)
|
motors.largeA.setSpeed(75)
|
||||||
loops.pause(20000)
|
pause(20000)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ Run the motor connected to port **A** continuously. Pause 20 seconds and then st
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
motors.largeA.setSpeed(75)
|
motors.largeA.setSpeed(75)
|
||||||
loops.pause(20000)
|
pause(20000)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ Run the motor connected to port **A** in reverse. Pause 5 seconds and then stop
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
motors.largeA.setSpeed(-60)
|
motors.largeA.setSpeed(-60)
|
||||||
loops.pause(5000)
|
pause(5000)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ motors.largeA.setRegulated(false)
|
|||||||
motors.largeA.setSpeed(55)
|
motors.largeA.setSpeed(55)
|
||||||
brick.showString("Actual speed:", 1)
|
brick.showString("Actual speed:", 1)
|
||||||
for (let i = 0; i < 30; i++) {
|
for (let i = 0; i < 30; i++) {
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
brick.showNumber(motors.largeA.speed(), 3)
|
brick.showNumber(motors.largeA.speed(), 3)
|
||||||
}
|
}
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
|
@ -14,9 +14,9 @@ Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
motors.largeA.setSpeed(30)
|
motors.largeA.setSpeed(30)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
motors.largeA.setSpeed(50)
|
motors.largeA.setSpeed(50)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ Run the motor connected to port **A** at half speed for 5 seconds. Display the n
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
motors.largeA.setSpeed(50)
|
motors.largeA.setSpeed(50)
|
||||||
loops.pause(5000)
|
pause(5000)
|
||||||
motors.largeA.stop()
|
motors.largeA.stop()
|
||||||
brick.showString("Motor rotations:", 1)
|
brick.showString("Motor rotations:", 1)
|
||||||
brick.showNumber(motors.largeA.tacho() / 360, 3)
|
brick.showNumber(motors.largeA.tacho() / 360, 3)
|
||||||
|
@ -14,7 +14,7 @@ Tank the @boardname@ forward at half speed for 5 seconds and then stop.
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
motors.largeAB.tank(50, 50);
|
motors.largeAB.tank(50, 50);
|
||||||
loops.pause(5000);
|
pause(5000);
|
||||||
motors.stopAll();
|
motors.stopAll();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -72,9 +72,9 @@ Steer the brick in a snake pattern for a short time.
|
|||||||
```block
|
```block
|
||||||
for (let i = 0; i < 4; i++) {
|
for (let i = 0; i < 4; i++) {
|
||||||
motors.largeBC.steer(30, 30)
|
motors.largeBC.steer(30, 30)
|
||||||
loops.pause(5000)
|
pause(5000)
|
||||||
motors.largeBC.steer(-30, 30)
|
motors.largeBC.steer(-30, 30)
|
||||||
loops.pause(5000)
|
pause(5000)
|
||||||
}
|
}
|
||||||
motors.stopAll()
|
motors.stopAll()
|
||||||
```
|
```
|
||||||
|
@ -43,9 +43,9 @@ Move the brick straight ahead and then go backward.
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
motors.largeAB.tank(75, 75)
|
motors.largeAB.tank(75, 75)
|
||||||
loops.pause(10000)
|
pause(10000)
|
||||||
motors.largeAB.tank(-55, -55)
|
motors.largeAB.tank(-55, -55)
|
||||||
loops.pause(10000)
|
pause(10000)
|
||||||
motors.stopAll()
|
motors.stopAll()
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ Run both motors in opposite directions to spin the brick around to the left.
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
motors.largeAB.tank(-30, 30)
|
motors.largeAB.tank(-30, 30)
|
||||||
loops.pause(5000)
|
pause(5000)
|
||||||
motors.stopAll()
|
motors.stopAll()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
8
libs/base/shims.d.ts
vendored
8
libs/base/shims.d.ts
vendored
@ -70,17 +70,17 @@ declare namespace loops {
|
|||||||
* Repeats the code forever in the background. On each iteration, allows other codes to run.
|
* Repeats the code forever in the background. On each iteration, allows other codes to run.
|
||||||
* @param body code to execute
|
* @param body code to execute
|
||||||
*/
|
*/
|
||||||
//% help=loops/forever weight=100 afterOnStart=true
|
//% help=loops/forever weight=100 afterOnStart=true deprecated=true
|
||||||
//% blockId=forever block="forever" blockAllowMultiple=1 shim=loops::forever
|
//% blockId=forever_deprecated block="forever" blockAllowMultiple=1 shim=loops::forever
|
||||||
function forever(a: () => void): void;
|
function forever(a: () => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pause for the specified time in milliseconds
|
* Pause for the specified time in milliseconds
|
||||||
* @param ms how long to pause for, eg: 100, 200, 500, 1000, 2000
|
* @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"
|
//% async block="pause %pause=timePicker|ms"
|
||||||
//% blockId=device_pause shim=loops::pause
|
//% blockId=device_pause_deprecated shim=loops::pause
|
||||||
function pause(ms: int32): void;
|
function pause(ms: int32): void;
|
||||||
}
|
}
|
||||||
declare namespace control {
|
declare namespace control {
|
||||||
|
@ -294,7 +294,7 @@ namespace sensors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wait a bit
|
// wait a bit
|
||||||
loops.pause(50);
|
pause(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply tolerance
|
// apply tolerance
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Ambient Light
|
# Ambient Light
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
if (sensors.color1.ambientLight() > 20) {
|
if (sensors.color1.ambientLight() > 20) {
|
||||||
brick.setStatusLight(StatusLight.Green)
|
brick.setStatusLight(StatusLight.Green)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# color
|
# color
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
if (sensors.color1.color() == ColorSensorColor.Green) {
|
if (sensors.color1.color() == ColorSensorColor.Green) {
|
||||||
brick.setStatusLight(StatusLight.Green)
|
brick.setStatusLight(StatusLight.Green)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Reflected Light
|
# Reflected Light
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
if (sensors.color1.reflectedLight() > 20) {
|
if (sensors.color1.reflectedLight() > 20) {
|
||||||
brick.setStatusLight(StatusLight.Green)
|
brick.setStatusLight(StatusLight.Green)
|
||||||
} else {
|
} else {
|
||||||
|
@ -15,7 +15,7 @@ namespace sensors.internal {
|
|||||||
let prev = query()
|
let prev = query()
|
||||||
changeHandler(prev, prev)
|
changeHandler(prev, prev)
|
||||||
while (true) {
|
while (true) {
|
||||||
loops.pause(periodMs)
|
pause(periodMs)
|
||||||
let curr = query()
|
let curr = query()
|
||||||
if (prev !== curr) {
|
if (prev !== curr) {
|
||||||
changeHandler(prev, curr)
|
changeHandler(prev, curr)
|
||||||
@ -57,9 +57,9 @@ namespace sensors.internal {
|
|||||||
uartMM = control.mmap("/dev/lms_uart", UartOff.Size, 0)
|
uartMM = control.mmap("/dev/lms_uart", UartOff.Size, 0)
|
||||||
if (!uartMM) control.fail("no uart sensor")
|
if (!uartMM) control.fail("no uart sensor")
|
||||||
|
|
||||||
loops.forever(() => {
|
forever(() => {
|
||||||
detectDevices()
|
detectDevices()
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
})
|
})
|
||||||
|
|
||||||
for (let info_ of sensorInfos) {
|
for (let info_ of sensorInfos) {
|
||||||
@ -258,7 +258,7 @@ namespace sensors.internal {
|
|||||||
if (port < 0) return 0
|
if (port < 0) return 0
|
||||||
let s = getUartStatus(port)
|
let s = getUartStatus(port)
|
||||||
if (s) return s
|
if (s) return s
|
||||||
loops.pause(25)
|
pause(25)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ namespace sensors.internal {
|
|||||||
|
|
||||||
uartMM.setNumber(NumberFormat.Int8LE, UartOff.Status + port,
|
uartMM.setNumber(NumberFormat.Int8LE, UartOff.Status + port,
|
||||||
getUartStatus(port) & 0xfffe)
|
getUartStatus(port) & 0xfffe)
|
||||||
loops.pause(10)
|
pause(10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ namespace sensors.internal {
|
|||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
loops.pause(10)
|
pause(10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ namespace motors {
|
|||||||
// if we've recently completed a motor command with brake
|
// if we've recently completed a motor command with brake
|
||||||
// allow 500ms for robot to settle
|
// allow 500ms for robot to settle
|
||||||
if(this._brake)
|
if(this._brake)
|
||||||
loops.pause(500);
|
pause(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,15 +31,15 @@ brick.buttonUp.onEvent(ButtonEvent.Bumped, () => {
|
|||||||
|
|
||||||
let num = 0
|
let num = 0
|
||||||
|
|
||||||
loops.forever(() => {
|
forever(() => {
|
||||||
serial.writeDmesg()
|
serial.writeDmesg()
|
||||||
loops.pause(100)
|
pause(100)
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
loops.forever(() => {
|
forever(() => {
|
||||||
let v = input.color.getColor()
|
let v = input.color.getColor()
|
||||||
screen.print(10, 60, v + " ")
|
screen.print(10, 60, v + " ")
|
||||||
loops.pause(200)
|
pause(200)
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
|
@ -41,7 +41,7 @@ namespace control {
|
|||||||
//% blockId=timerPauseUntil block="%timer|pause until (ms) %ms"
|
//% blockId=timerPauseUntil block="%timer|pause until (ms) %ms"
|
||||||
pauseUntil(ms: number) {
|
pauseUntil(ms: number) {
|
||||||
const remaining = this.millis() - ms;
|
const remaining = this.millis() - ms;
|
||||||
loops.pause(Math.max(0, remaining));
|
pause(Math.max(0, remaining));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// This is the last thing executed before user code
|
// 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
|
// We pause for 100ms to give time to read sensor values, so they work in on_start block
|
||||||
loops.pause(100)
|
pause(100)
|
||||||
|
@ -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.
|
Flash the status light to red if the roll rate of `gyro 2` is more that `30` degrees per second.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
if (sensors.gyro2.rate() > 30) {
|
if (sensors.gyro2.rate() > 30) {
|
||||||
brick.setStatusLight(StatusLight.RedFlash)
|
brick.setStatusLight(StatusLight.RedFlash)
|
||||||
} else {
|
} else {
|
||||||
|
@ -95,7 +95,7 @@ namespace sensors {
|
|||||||
this.calibrating = true;
|
this.calibrating = true;
|
||||||
// may be triggered by a button click,
|
// may be triggered by a button click,
|
||||||
// give time for robot to settle
|
// give time for robot to settle
|
||||||
loops.pause(700);
|
pause(700);
|
||||||
// send a reset command
|
// send a reset command
|
||||||
super.reset();
|
super.reset();
|
||||||
// switch back to the desired mode
|
// switch back to the desired mode
|
||||||
@ -103,13 +103,13 @@ namespace sensors {
|
|||||||
// wait till sensor is live
|
// wait till sensor is live
|
||||||
pauseUntil(() => this.isActive());
|
pauseUntil(() => this.isActive());
|
||||||
// give it a bit of time to init
|
// give it a bit of time to init
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
// compute drift
|
// compute drift
|
||||||
this._drift = 0;
|
this._drift = 0;
|
||||||
if (this.mode == GyroSensorMode.Rate) {
|
if (this.mode == GyroSensorMode.Rate) {
|
||||||
for (let i = 0; i < 200; ++i) {
|
for (let i = 0; i < 200; ++i) {
|
||||||
this._drift += this._query();
|
this._drift += this._query();
|
||||||
loops.pause(4);
|
pause(4);
|
||||||
}
|
}
|
||||||
this._drift /= 200;
|
this._drift /= 200;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ namespace brick {
|
|||||||
brick.setStatusLight(this.light);
|
brick.setStatusLight(this.light);
|
||||||
brick.showImage(this.image);
|
brick.showImage(this.image);
|
||||||
music.playSoundEffectUntilDone(this.sound);
|
music.playSoundEffectUntilDone(this.sound);
|
||||||
loops.pause(20);
|
pause(20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
music.setVolume(3)
|
music.setVolume(3)
|
||||||
music.playTone(440, 500)
|
music.playTone(440, 500)
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
music.playTone(1440, 500)
|
music.playTone(1440, 500)
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
music.playTone(2440, 500)
|
music.playTone(2440, 500)
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
|
@ -9,7 +9,7 @@ Tests are registered as event handlers. They will automatically run once ``on st
|
|||||||
```blocks
|
```blocks
|
||||||
tests.test("lgB set speed 10", () => {
|
tests.test("lgB set speed 10", () => {
|
||||||
motors.largeB.setSpeed(10);
|
motors.largeB.setSpeed(10);
|
||||||
loops.pause(100)
|
pause(100)
|
||||||
tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
|
tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -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`.
|
If the touch sensor ``touch 1`` is pressed, show a `green` status light. Otherwise, set the status light to `orange`.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
if (sensors.touch1.isPressed()) {
|
if (sensors.touch1.isPressed()) {
|
||||||
brick.setStatusLight(StatusLight.Green)
|
brick.setStatusLight(StatusLight.Green)
|
||||||
} else {
|
} else {
|
||||||
|
@ -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`.
|
If the touch sensor ``touch 1`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
loops.forever(function () {
|
forever(function () {
|
||||||
if (sensors.touch1.wasPressed()) {
|
if (sensors.touch1.wasPressed()) {
|
||||||
brick.setStatusLight(StatusLight.Green)
|
brick.setStatusLight(StatusLight.Green)
|
||||||
} else {
|
} else {
|
||||||
brick.setStatusLight(StatusLight.Orange)
|
brick.setStatusLight(StatusLight.Orange)
|
||||||
}
|
}
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ tests.test("Bright ambient light", function () {
|
|||||||
let actualLight: number
|
let actualLight: number
|
||||||
for (let i = 0; i < 4; i++) {
|
for (let i = 0; i < 4; i++) {
|
||||||
actualLight = sensors.color1.ambientLight()
|
actualLight = sensors.color1.ambientLight()
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
}
|
}
|
||||||
tests.assertClose("Light", actualLight, 20, 15)
|
tests.assertClose("Light", actualLight, 20, 15)
|
||||||
})
|
})
|
||||||
@ -29,7 +29,7 @@ tests.test("Bright reflected light", function () {
|
|||||||
let actualLight: number
|
let actualLight: number
|
||||||
for (let i = 0; i < 4; i++) {
|
for (let i = 0; i < 4; i++) {
|
||||||
actualLight = sensors.color1.reflectedLight()
|
actualLight = sensors.color1.reflectedLight()
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
}
|
}
|
||||||
tests.assertClose("Light", actualLight, 17, 14)
|
tests.assertClose("Light", actualLight, 17, 14)
|
||||||
})
|
})
|
@ -1,42 +1,42 @@
|
|||||||
// add tests package
|
// add tests package
|
||||||
tests.test("lgB set speed 10", () => {
|
tests.test("lgB set speed 10", () => {
|
||||||
motors.largeB.setSpeed(10);
|
motors.largeB.setSpeed(10);
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
|
tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
|
||||||
});
|
});
|
||||||
tests.test("lgB set speed 25 (reversed)", () => {
|
tests.test("lgB set speed 25 (reversed)", () => {
|
||||||
motors.largeB.setInverted(true)
|
motors.largeB.setInverted(true)
|
||||||
motors.largeB.setSpeed(25)
|
motors.largeB.setSpeed(25)
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
tests.assertClose("speedB", -25, motors.largeB.speed(), 2)
|
tests.assertClose("speedB", -25, motors.largeB.speed(), 2)
|
||||||
});
|
});
|
||||||
tests.test("lgBC set speed 5", () => {
|
tests.test("lgBC set speed 5", () => {
|
||||||
motors.largeBC.setSpeed(5)
|
motors.largeBC.setSpeed(5)
|
||||||
loops.pause(500)
|
pause(500)
|
||||||
tests.assertClose("speedB", 5, motors.largeB.speed(), 1);
|
tests.assertClose("speedB", 5, motors.largeB.speed(), 1);
|
||||||
tests.assertClose("speedC", 5, motors.largeC.speed(), 1);
|
tests.assertClose("speedC", 5, motors.largeC.speed(), 1);
|
||||||
});
|
});
|
||||||
tests.test("lgBC steer 50% 2x", () => {
|
tests.test("lgBC steer 50% 2x", () => {
|
||||||
motors.largeBC.setBrake(true)
|
motors.largeBC.setBrake(true)
|
||||||
motors.largeBC.steer(50, 50, 1, MoveUnit.Rotations)
|
motors.largeBC.steer(50, 50, 1, MoveUnit.Rotations)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
tests.assertClose("largeB", 360, motors.largeB.angle(), 5)
|
tests.assertClose("largeB", 360, motors.largeB.angle(), 5)
|
||||||
motors.largeBC.setBrake(false)
|
motors.largeBC.setBrake(false)
|
||||||
})
|
})
|
||||||
tests.test("lgBC steer 360deg", () => {
|
tests.test("lgBC steer 360deg", () => {
|
||||||
motors.largeBC.setBrake(true)
|
motors.largeBC.setBrake(true)
|
||||||
motors.largeBC.steer(50, 50, 360, MoveUnit.Degrees)
|
motors.largeBC.steer(50, 50, 360, MoveUnit.Degrees)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
tests.assertClose("largeB", 360, motors.largeB.angle(), 5)
|
tests.assertClose("largeB", 360, motors.largeB.angle(), 5)
|
||||||
});
|
});
|
||||||
tests.test("lgBC steer 50% 1s", () => {
|
tests.test("lgBC steer 50% 1s", () => {
|
||||||
motors.largeBC.setBrake(true)
|
motors.largeBC.setBrake(true)
|
||||||
motors.largeBC.steer(10, 50, 1000, MoveUnit.MilliSeconds)
|
motors.largeBC.steer(10, 50, 1000, MoveUnit.MilliSeconds)
|
||||||
loops.pause(2000)
|
pause(2000)
|
||||||
})
|
})
|
||||||
tests.test("lgBC tank 50% 180deg", () => {
|
tests.test("lgBC tank 50% 180deg", () => {
|
||||||
motors.largeBC.setBrake(true)
|
motors.largeBC.setBrake(true)
|
||||||
motors.largeBC.tank(50, 50, 180, MoveUnit.Degrees)
|
motors.largeBC.tank(50, 50, 180, MoveUnit.Degrees)
|
||||||
loops.pause(1000)
|
pause(1000)
|
||||||
tests.assertClose("largeB", 180, motors.largeB.angle(), 5)
|
tests.assertClose("largeB", 180, motors.largeB.angle(), 5)
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user