Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
05e916e247 | |||
fad4ca98db | |||
3b6cfed5b2 | |||
472ea170d0 | |||
80f24948ec | |||
daa88b299d | |||
0384eb4d9d | |||
f33f88e87c | |||
239827c259 | |||
cd0097749a | |||
94db31beb7 | |||
408631d426 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -17,8 +17,6 @@ clients/**/bin/**
|
||||
clients/**/obj/**
|
||||
clients/electron/projects
|
||||
libs/**/_locales/**
|
||||
libs/**/shims.d.ts
|
||||
libs/**/enums.d.ts
|
||||
|
||||
videos/**
|
||||
|
||||
|
10
README.md
10
README.md
@ -2,7 +2,7 @@
|
||||
|
||||
[](https://ci2.dot.net/job/Private/job/pxt_project_rainbow/job/master/job/pxt-ev3_Push/)
|
||||
|
||||
This repo contains the editor target hosted at https://d541eec2-1e96-4b7b-a223-da9d01d0337a.pxt.io/
|
||||
This repo contains the editor target hosted at https://makecode.legoeducation.com
|
||||
|
||||
LEGO Auth: https://src.education.lego.com/groups/ev3-makecode (use Google Authenticator)
|
||||
LEGO Chat: https://chat.internal.education.lego.com/make-code/channels/town-square
|
||||
@ -11,7 +11,7 @@ LEGO Chat: https://chat.internal.education.lego.com/make-code/channels/town-squa
|
||||
|
||||
These instructions assume familiarity with dev tools and languages.
|
||||
|
||||
* install Node.js 6+
|
||||
* install Node.js 8.9.4+
|
||||
* install Docker; make sure `docker` command is in your `PATH`
|
||||
* (optional) install [Visual Studio Code](https://code.visualstudio.com/)
|
||||
|
||||
@ -58,12 +58,6 @@ cd libs/core
|
||||
pxt deploy
|
||||
```
|
||||
|
||||
### Hosted editor
|
||||
|
||||
Currently hosted at:
|
||||
|
||||
https://d541eec2-1e96-4b7b-a223-da9d01d0337a.pxt.io/
|
||||
|
||||
### Jenkins build
|
||||
https://ci2.dot.net/job/Private/job/pxt_project_rainbow/job/master/
|
||||
|
||||
|
@ -67,7 +67,7 @@
|
||||
* [set light](/reference/brick/set-status-light)
|
||||
* [battery level](/reference/brick/battery-level)
|
||||
* [Motors](/reference/motors)
|
||||
* [set speed](/reference/motors/motor/set-speed)
|
||||
* [run](/reference/motors/motor/run)
|
||||
* [stop](/reference/motors/motor/stop)
|
||||
* [reset](/reference/motors/motor/reset)
|
||||
* [set brake](/reference/motors/motor/set-brake)
|
||||
|
@ -8,12 +8,12 @@ You can program the @boardname@ using [Blocks](/blocks) or [JavaScript](/javascr
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
```
|
||||
```typescript
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
```
|
||||
|
||||
@ -34,6 +34,6 @@ The simulator has support for the LED screen, buttons, as well as compass, accel
|
||||
|
||||
```sim
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
```
|
||||
|
@ -3,6 +3,6 @@
|
||||
### #specific
|
||||
|
||||
```cards
|
||||
loops.forever(() => {});
|
||||
loops.pause(0)
|
||||
forever(() => {});
|
||||
pause(0)
|
||||
```
|
@ -5,6 +5,6 @@ let speed = 0;
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed < 100)
|
||||
speed = speed + 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
motors.largeBC.run(speed);
|
||||
})
|
||||
```
|
@ -5,11 +5,11 @@ let speed = 0;
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed < 100)
|
||||
speed = speed + 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
motors.largeBC.run(speed);
|
||||
})
|
||||
sensors.touch2.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed > -100)
|
||||
speed = speed - 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
motors.largeBC.run(speed);
|
||||
})
|
||||
```
|
@ -15,7 +15,7 @@ function accelerate() {
|
||||
function update() {
|
||||
brick.clearScreen()
|
||||
brick.showString("speed: " + speed, 1)
|
||||
motors.largeBC.setSpeed(speed)
|
||||
motors.largeBC.run(speed)
|
||||
}
|
||||
sensors.touch2.onEvent(ButtonEvent.Pressed, function () {
|
||||
accelerate()
|
||||
|
@ -7,6 +7,6 @@ while (true) {
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||
}
|
||||
loops.pause(1);
|
||||
pause(1);
|
||||
}
|
||||
```
|
||||
|
@ -8,6 +8,6 @@ while (true) {
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
|
||||
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
|
||||
}
|
||||
loops.pause(1);
|
||||
pause(1);
|
||||
}
|
||||
```
|
||||
|
@ -3,7 +3,7 @@
|
||||
```blocks
|
||||
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
|
||||
brick.showImage(images.objectsLightOn)
|
||||
loops.pause(5000)
|
||||
pause(5000)
|
||||
brick.clearScreen()
|
||||
})
|
||||
```
|
@ -1,11 +1,11 @@
|
||||
# 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);
|
||||
motors.largeBC.run(-20);
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
||||
motors.largeBC.stop();
|
||||
```
|
||||
|
@ -1,13 +1,13 @@
|
||||
# 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);
|
||||
motors.largeBC.run(-20);
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
||||
motors.largeBC.stop();
|
||||
```
|
||||
|
@ -4,7 +4,7 @@
|
||||
let beep = false
|
||||
beep = true
|
||||
control.runInParallel(function () {
|
||||
motors.largeBC.setSpeed(-20)
|
||||
motors.largeBC.run(-20)
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
|
||||
motors.largeBC.stop()
|
||||
beep = false
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.setSpeed(50)
|
||||
motors.largeBC.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(0)
|
||||
loops.pause(1000)
|
||||
motors.largeBC.run(0)
|
||||
pause(1000)
|
||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||
motors.largeBC.setSpeed(-50)
|
||||
loops.pause(2000)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(-50)
|
||||
pause(2000)
|
||||
motors.largeBC.run(0)
|
||||
})
|
||||
```
|
@ -3,13 +3,13 @@
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(50)
|
||||
motors.largeBC.run(50)
|
||||
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(0)
|
||||
loops.pause(1000)
|
||||
motors.largeBC.run(0)
|
||||
pause(1000)
|
||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||
motors.largeBC.setSpeed(-50)
|
||||
loops.pause(2000)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(-50)
|
||||
pause(2000)
|
||||
motors.largeBC.run(0)
|
||||
})
|
||||
```
|
@ -5,15 +5,15 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
brick.showImage(images.eyesSleeping)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
brick.showImage(images.eyesNeutral)
|
||||
motors.largeBC.setSpeed(50)
|
||||
motors.largeBC.run(50)
|
||||
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
||||
brick.showImage(images.eyesTiredMiddle)
|
||||
motors.largeBC.setSpeed(0)
|
||||
loops.pause(1000)
|
||||
motors.largeBC.run(0)
|
||||
pause(1000)
|
||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||
brick.showImage(images.eyesDizzy)
|
||||
motors.largeBC.setSpeed(-50)
|
||||
loops.pause(2000)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(-50)
|
||||
pause(2000)
|
||||
motors.largeBC.run(0)
|
||||
})
|
||||
```
|
@ -15,17 +15,17 @@ 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) {
|
||||
motors.largeC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeC.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 3) {
|
||||
motors.largeB.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeB.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 4) {
|
||||
motors.largeBC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(50, 360, MoveUnit.Degrees)
|
||||
} else {
|
||||
motors.largeBC.setSpeed(-50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(-50, 360, MoveUnit.Degrees)
|
||||
}
|
||||
}
|
||||
music.playSoundEffectUntilDone(sounds.communicationGameOver)
|
||||
|
@ -19,17 +19,17 @@ 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) {
|
||||
motors.largeC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeC.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 3) {
|
||||
motors.largeB.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeB.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 4) {
|
||||
motors.largeBC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(50, 360, MoveUnit.Degrees)
|
||||
} else {
|
||||
motors.largeBC.setSpeed(-50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(-50, 360, MoveUnit.Degrees)
|
||||
}
|
||||
}
|
||||
music.playSoundEffectUntilDone(sounds.communicationGameOver)
|
||||
|
@ -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)
|
||||
})
|
||||
```
|
@ -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)
|
||||
})
|
||||
```
|
@ -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)
|
||||
})
|
||||
```
|
@ -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 {
|
||||
|
@ -32,7 +32,7 @@ Think about examples from your brainstorming discussion. Then explain why you ch
|
||||
|
||||

|
||||
|
||||
https://www.youtube.com/watch?v=ErC_s3hLGMk
|
||||
https://www.youtube.com/ErC_s3hLGMk
|
||||
|
||||
## Construct
|
||||
|
||||
@ -56,13 +56,13 @@ As you test your design solution, use the table for recording your findings.
|
||||
|
||||
[**VIEW BUILDING INSTRUCTIONS**](TODO) for a sample solution. (7.8 MB, PDF)
|
||||
|
||||
# Contemplate
|
||||
## Contemplate
|
||||
|
||||
## Test and Analyze
|
||||
### Test and Analyze
|
||||
|
||||
How well does your solution satisfy the design brief? Record your data. Name the columns and rows, such as Trial Number, Distance Moved, and Observations.
|
||||
|
||||
## Review and Revise
|
||||
### Review and Revise
|
||||
|
||||
Take a moment to reflect on your robot solution.
|
||||
|
||||
@ -72,9 +72,9 @@ Think about:
|
||||
* Is it accurate? How do you know?
|
||||
Describe two ways you could improve your robot.
|
||||
|
||||
# Continue
|
||||
## Continue
|
||||
|
||||
## Communicate
|
||||
### Communicate
|
||||
|
||||
Here are some ideas:
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance.
|
||||
|
@ -212,5 +212,10 @@ Here are some fun programs for your @boardname@!
|
||||
"description": "Keep your brick entertained and happy",
|
||||
"url":"/examples/happy-unhappy",
|
||||
"cardType": "example"
|
||||
}, {
|
||||
"name": "Distance Measurer",
|
||||
"description": "Use a motor to measure angle and distance",
|
||||
"url": "/examples/distance-measurer",
|
||||
"cardType": "example"
|
||||
}]
|
||||
```
|
@ -119,15 +119,15 @@ sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
|
||||
controlSteering = 0
|
||||
oldControlDrive = controlDrive
|
||||
controlDrive = -10
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
if (Math.randomRange(-1, 1) >= 1) {
|
||||
controlSteering = 70
|
||||
} else {
|
||||
controlSteering = -70
|
||||
}
|
||||
loops.pause(4000)
|
||||
pause(4000)
|
||||
music.playTone(2000, 100)
|
||||
controlSteering = 0
|
||||
controlDrive = oldControlDrive
|
||||
@ -149,8 +149,8 @@ sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
|
||||
})
|
||||
// apply power to motors
|
||||
function controlMotors() {
|
||||
motors.largeA.setSpeed(power + controlSteering * 0.1)
|
||||
motors.largeD.setSpeed(power - controlSteering * 0.1)
|
||||
motors.largeA.run(power + controlSteering * 0.1)
|
||||
motors.largeD.run(power - controlSteering * 0.1)
|
||||
}
|
||||
sensors.color1.onColorDetected(ColorSensorColor.Yellow, function () {
|
||||
moods.middleLeft.show()
|
||||
@ -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)
|
||||
|
@ -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()
|
||||
@ -137,12 +137,12 @@ loops.forever(function () {
|
||||
GM();
|
||||
EQ();
|
||||
cntrl();
|
||||
motors.largeA.setSpeed(lpwr)
|
||||
motors.largeD.setSpeed(rpwr)
|
||||
motors.largeA.run(lpwr)
|
||||
motors.largeD.run(rpwr)
|
||||
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;
|
||||
@ -196,20 +196,20 @@ loops.forever(function () {
|
||||
Cstr = 0;
|
||||
oldDr = Cdrv;
|
||||
Cdrv = -10;
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
if (Math.randomRange(-1, 1) >= 1)
|
||||
Cstr = 70;
|
||||
else
|
||||
Cstr = -70;
|
||||
loops.pause(4000);
|
||||
pause(4000);
|
||||
music.playTone(2000, 100)
|
||||
Cstr = 0;
|
||||
Cdrv = oldDr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
loops.pause(80);
|
||||
pause(80);
|
||||
})
|
||||
```
|
@ -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()
|
||||
}
|
||||
@ -32,9 +32,9 @@ function MNRH() {
|
||||
brick.setStatusLight(StatusLight.OrangePulse)
|
||||
while (!brick.buttonEnter.wasPressed()) {
|
||||
if (brick.buttonUp.wasPressed()) {
|
||||
motors.mediumC.setSpeed(-100);
|
||||
motors.mediumC.run(-100);
|
||||
} else if (brick.buttonDown.wasPressed()) {
|
||||
motors.mediumC.setSpeed(100);
|
||||
motors.mediumC.run(100);
|
||||
} else {
|
||||
motors.mediumC.stop();
|
||||
}
|
||||
@ -83,24 +83,24 @@ function UP() {
|
||||
if (motors.largeA.angle() > -50) {
|
||||
control.runInParallel(function () {
|
||||
motors.largeD.clearCounts()
|
||||
motors.largeD.setSpeed(-35);
|
||||
motors.largeD.run(-35);
|
||||
pauseUntil(() => motors.largeD.angle() < -25);
|
||||
motors.largeD.stop();
|
||||
motors.largeD.setRegulated(false)
|
||||
motors.largeD.setSpeed(-15)
|
||||
motors.largeD.run(-15)
|
||||
pauseUntil(() => motors.largeD.angle() < -65);
|
||||
motors.largeD.stop();
|
||||
})
|
||||
motors.largeA.clearCounts()
|
||||
motors.largeA.setSpeed(-35);
|
||||
motors.largeA.run(-35);
|
||||
pauseUntil(() => motors.largeA.angle() < -25);
|
||||
motors.largeA.stop();
|
||||
motors.largeA.setRegulated(false)
|
||||
motors.largeA.setSpeed(-15)
|
||||
motors.largeA.run(-15)
|
||||
pauseUntil(() => motors.largeA.angle() < -65);
|
||||
motors.largeA.stop();
|
||||
|
||||
loops.pause(500);
|
||||
pause(500);
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,9 +231,9 @@ function IDL() {
|
||||
function MHT(Pos: number) {
|
||||
let _R = Pos - motors.mediumC.angle();
|
||||
if (_R >= 0) {
|
||||
motors.mediumC.setSpeed(100, _R, MoveUnit.Degrees);
|
||||
motors.mediumC.run(100, _R, MoveUnit.Degrees);
|
||||
} else {
|
||||
motors.mediumC.setSpeed(-100, Math.abs(_R), MoveUnit.Degrees);
|
||||
motors.mediumC.run(-100, Math.abs(_R), MoveUnit.Degrees);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,16 +303,16 @@ function PPP() {
|
||||
NS = false;
|
||||
IS(2);
|
||||
UP();
|
||||
loops.pause(100)
|
||||
motors.largeA.setSpeed(-30, 70, MoveUnit.Degrees);
|
||||
loops.pause(800);
|
||||
pause(100)
|
||||
motors.largeA.run(-30, 70, MoveUnit.Degrees);
|
||||
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);
|
||||
motors.largeA.run(-30, 20, MoveUnit.Degrees);
|
||||
motors.largeA.run(30, 20, MoveUnit.Degrees);
|
||||
}
|
||||
motors.largeA.setSpeed(30, 70, MoveUnit.Degrees);
|
||||
motors.largeA.run(30, 70, MoveUnit.Degrees);
|
||||
F_C = 1;
|
||||
CS(0);
|
||||
}
|
||||
@ -320,14 +320,14 @@ function PPP() {
|
||||
function HPY() {
|
||||
IS(8)
|
||||
MHT(0);
|
||||
motors.largeAD.setSpeed(10, 0.8, MoveUnit.Seconds);
|
||||
motors.largeAD.run(10, 0.8, MoveUnit.Seconds);
|
||||
for(let i = 0; i < 3; ++i) {
|
||||
music.playSoundEffect(sounds.animalsDogBark1);
|
||||
motors.largeAD.setSpeed(-100, 0.2, MoveUnit.Seconds);
|
||||
loops.pause(300)
|
||||
motors.largeAD.setSpeed(10, 0.3, MoveUnit.Seconds)
|
||||
motors.largeAD.run(-100, 0.2, MoveUnit.Seconds);
|
||||
pause(300)
|
||||
motors.largeAD.run(10, 0.3, MoveUnit.Seconds)
|
||||
}
|
||||
loops.pause(500);
|
||||
pause(500);
|
||||
music.stopAllSounds();
|
||||
DN();
|
||||
RST();
|
||||
@ -335,9 +335,9 @@ function HPY() {
|
||||
|
||||
function STL() {
|
||||
UP();
|
||||
motors.largeAD.setSpeed(-20, 60, MoveUnit.Degrees);
|
||||
motors.largeAD.run(-20, 60, MoveUnit.Degrees);
|
||||
music.playSoundEffect(sounds.animalsDogWhine);
|
||||
motors.largeAD.setSpeed(20, 60, MoveUnit.Degrees);
|
||||
motors.largeAD.run(20, 60, MoveUnit.Degrees);
|
||||
}
|
||||
|
||||
function WKU() {
|
||||
@ -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:
|
||||
|
@ -5,20 +5,20 @@ function INI() {
|
||||
motors.largeB.setBrake(true)
|
||||
motors.largeC.setBrake(true)
|
||||
motors.mediumA.setBrake(true)
|
||||
motors.largeB.setSpeed(-50)
|
||||
motors.largeB.run(-50)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.setSpeed(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.setSpeed(50)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.run(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed);
|
||||
motors.largeC.setSpeed(-50, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-50, 0.86, MoveUnit.Rotations);
|
||||
}
|
||||
|
||||
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())
|
||||
@ -27,24 +27,24 @@ loops.forever(function () {
|
||||
brick.showImage(images.informationAccept)
|
||||
if (down) {
|
||||
brick.showImage(images.informationForward)
|
||||
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(65, 0.85, MoveUnit.Rotations);
|
||||
} else {
|
||||
brick.showImage(images.informationBackward)
|
||||
motors.largeC.setSpeed(-65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(-65, 0.85, MoveUnit.Rotations);
|
||||
}
|
||||
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees)
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
if (down) {
|
||||
motors.largeC.setSpeed(-65, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-65, 0.86, MoveUnit.Rotations);
|
||||
} else {
|
||||
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(65, 0.85, MoveUnit.Rotations);
|
||||
}
|
||||
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees);
|
||||
motors.mediumA.setSpeed(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees);
|
||||
motors.mediumA.run(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop()
|
||||
})
|
||||
|
@ -5,20 +5,20 @@ function INI() {
|
||||
motors.largeB.setBrake(true)
|
||||
motors.largeC.setBrake(true)
|
||||
motors.mediumA.setBrake(true)
|
||||
motors.largeB.setSpeed(-50)
|
||||
motors.largeB.run(-50)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.setSpeed(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.setSpeed(50)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.run(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed);
|
||||
motors.largeC.setSpeed(-50, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-50, 0.86, MoveUnit.Rotations);
|
||||
}
|
||||
|
||||
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())
|
||||
@ -27,24 +27,24 @@ loops.forever(function () {
|
||||
brick.showImage(images.informationAccept)
|
||||
if (down) {
|
||||
brick.showImage(images.informationForward)
|
||||
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(65, 0.85, MoveUnit.Rotations);
|
||||
} else {
|
||||
brick.showImage(images.informationBackward)
|
||||
motors.largeC.setSpeed(-65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(-65, 0.85, MoveUnit.Rotations);
|
||||
}
|
||||
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees)
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
if (down) {
|
||||
motors.largeC.setSpeed(-65, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-65, 0.86, MoveUnit.Rotations);
|
||||
} else {
|
||||
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(65, 0.85, MoveUnit.Rotations);
|
||||
}
|
||||
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees);
|
||||
motors.mediumA.setSpeed(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees);
|
||||
motors.mediumA.run(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop()
|
||||
})
|
||||
|
34
docs/examples/distance-measurer.md
Normal file
34
docs/examples/distance-measurer.md
Normal file
@ -0,0 +1,34 @@
|
||||
# Distance Measurer
|
||||
|
||||
```blocks
|
||||
let distance = 0
|
||||
let angle = 0
|
||||
let measuring = false
|
||||
let radius = 0
|
||||
// Start and stop measuring with the enter button
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (measuring) {
|
||||
// turn off the measuring
|
||||
measuring = false
|
||||
brick.setStatusLight(StatusLight.Off)
|
||||
} else {
|
||||
// turn on the measuring clear the counters so that
|
||||
// the motor tracks the angle
|
||||
measuring = true
|
||||
motors.largeB.clearCounts()
|
||||
brick.setStatusLight(StatusLight.GreenPulse)
|
||||
}
|
||||
})
|
||||
radius = 2.5
|
||||
brick.showString("Press ENTER to measure", 4)
|
||||
forever(function () {
|
||||
if (measuring) {
|
||||
angle = motors.largeB.angle()
|
||||
distance = angle / 180 * Math.PI * radius
|
||||
brick.clearScreen()
|
||||
brick.showValue("angle", angle, 2)
|
||||
brick.showValue("distance", distance, 3)
|
||||
}
|
||||
pause(100)
|
||||
})
|
||||
```
|
@ -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()
|
||||
@ -137,12 +137,12 @@ loops.forever(function () {
|
||||
GM();
|
||||
EQ();
|
||||
cntrl();
|
||||
motors.largeA.setSpeed(lpwr)
|
||||
motors.largeD.setSpeed(rpwr)
|
||||
motors.largeA.run(lpwr)
|
||||
motors.largeD.run(rpwr)
|
||||
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;
|
||||
@ -196,20 +196,20 @@ loops.forever(function () {
|
||||
Cstr = 0;
|
||||
oldDr = Cdrv;
|
||||
Cdrv = -10;
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
if (Math.randomRange(-1, 1) >= 1)
|
||||
Cstr = 70;
|
||||
else
|
||||
Cstr = -70;
|
||||
loops.pause(4000);
|
||||
pause(4000);
|
||||
music.playTone(2000, 100)
|
||||
Cstr = 0;
|
||||
Cdrv = oldDr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
loops.pause(80);
|
||||
pause(80);
|
||||
})
|
||||
```
|
@ -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)
|
||||
@ -43,7 +43,7 @@ loops.forever(function () {
|
||||
motors.largeBC.steer(P + (I + D), 100)
|
||||
lasterror = error
|
||||
if (brick.buttonEnter.wasPressed()) {
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(0)
|
||||
brick.buttonDown.pauseUntil(ButtonEvent.Bumped)
|
||||
}
|
||||
})
|
||||
|
@ -14,16 +14,16 @@ Take a look a the LabView program below: it **starts**, turns on motor A, waits
|
||||
The blocks in MakeCode have similar functions and go together in the same way: they snap into the ``||loops:on start||`` block and then connect to each other vertically.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(1000)
|
||||
motors.largeA.run(50)
|
||||
pause(1000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
Any block program can be converted to JavaScript and you can edit it as lines of code too.
|
||||
|
||||
```typescript
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(1000)
|
||||
motors.largeA.run(50)
|
||||
pause(1000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
@ -40,10 +40,10 @@ This program controls a large motor on port A in several different ways. It sets
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(50);
|
||||
motors.largeA.setSpeed(50, 1000, MoveUnit.MilliSeconds);
|
||||
motors.largeA.setSpeed(50, 360, MoveUnit.Degrees);
|
||||
motors.largeA.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeA.run(50);
|
||||
motors.largeA.run(50, 1000, MoveUnit.MilliSeconds);
|
||||
motors.largeA.run(50, 360, MoveUnit.Degrees);
|
||||
motors.largeA.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeA.stop();
|
||||
```
|
||||
|
||||
@ -83,7 +83,7 @@ By default, all motors coast when any command used to move finishes. You can kee
|
||||
|
||||
```blocks
|
||||
motors.largeD.setBrake(true);
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations)
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations)
|
||||
```
|
||||
|
||||
## Inverting and regulating motors
|
||||
@ -132,15 +132,15 @@ 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)
|
||||
motors.largeD.run(50)
|
||||
pause(1000)
|
||||
motors.largeD.stop();
|
||||
```
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeD.stop();
|
||||
```
|
||||
@ -148,7 +148,7 @@ motors.largeD.stop();
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
|
||||
motors.largeD.stop();
|
||||
```
|
||||
@ -156,7 +156,7 @@ motors.largeD.stop();
|
||||
You can also use the ``||loops:pause until||`` block to wait on any [boolean](/types/boolean) expression. As your program runs, it waits until the condition (expression) inside becomes true.
|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
pauseUntil(() => sensors.touch1.isPressed())
|
||||
motors.largeD.stop()
|
||||
```
|
||||
@ -166,9 +166,9 @@ motors.largeD.stop()
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(() => {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
forever(() => {
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-50, 1, MoveUnit.Rotations);
|
||||
})
|
||||
```
|
||||
|
||||
@ -176,13 +176,13 @@ loops.forever(() => {
|
||||
|
||||
```blocks
|
||||
for(let i = 0; i < 10; i++) {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-50, 1, MoveUnit.Rotations);
|
||||
}
|
||||
let k = 0;
|
||||
while(k < 10) {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-50, 1, MoveUnit.Rotations);
|
||||
k++;
|
||||
}
|
||||
```
|
||||
@ -193,9 +193,9 @@ while(k < 10) {
|
||||
|
||||
```blocks
|
||||
let light = 0;
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
light = sensors.color3.light(LightIntensityMode.Reflected);
|
||||
motors.largeD.setSpeed(light)
|
||||
motors.largeD.run(light)
|
||||
})
|
||||
```
|
||||
|
||||
@ -206,15 +206,15 @@ You can start up multiple ``||loops:forever||`` loops that will run at the same
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(() => {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
forever(() => {
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-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,9 +225,9 @@ The ``||logic:if||`` block allows you to run different code depending on whether
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(function() {
|
||||
forever(function() {
|
||||
if(sensors.touch1.isPressed()) {
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
} else {
|
||||
motors.largeD.stop()
|
||||
}
|
||||
@ -241,8 +241,8 @@ The ``||math:pick random||`` block returns a random number selected from a range
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
motors.largeBC.steer(Math.randomRange(-5, 5), 50)
|
||||
loops.pause(100)
|
||||
pause(100)
|
||||
})
|
||||
```
|
@ -213,13 +213,13 @@ music.playSoundEffect(sounds.systemGeneralAlert)
|
||||
}
|
||||
while (true) {
|
||||
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeB.setSpeed(10)
|
||||
motors.largeC.setSpeed(-10)
|
||||
motors.largeB.run(10)
|
||||
motors.largeC.run(-10)
|
||||
}
|
||||
while (true) {
|
||||
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeA.setSpeed(-10)
|
||||
motors.largeA.setSpeed(10)
|
||||
motors.largeA.run(-10)
|
||||
motors.largeA.run(10)
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -235,13 +235,13 @@ You will need to constantly debug your program in order to make your robot trave
|
||||
```blocks
|
||||
while (true) {
|
||||
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeB.setSpeed(10)
|
||||
motors.largeC.setSpeed(-10)
|
||||
motors.largeB.run(10)
|
||||
motors.largeC.run(-10)
|
||||
}
|
||||
while (true) {
|
||||
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeB.setSpeed(-10)
|
||||
motors.largeC.setSpeed(10)
|
||||
motors.largeB.run(-10)
|
||||
motors.largeC.run(10)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -3,13 +3,13 @@
|
||||
Use this program with the Programmable Brick and Large Motor.
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(100)
|
||||
forever(function () {
|
||||
motors.largeA.run(30)
|
||||
pause(100)
|
||||
motors.largeA.stop()
|
||||
music.playSoundEffectUntilDone(sounds.animalsCatPurr)
|
||||
motors.largeA.setSpeed(-30)
|
||||
loops.pause(100)
|
||||
motors.largeA.run(-30)
|
||||
pause(100)
|
||||
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.
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(200)
|
||||
motors.largeA.setSpeed(100)
|
||||
loops.pause(200)
|
||||
forever(function () {
|
||||
motors.largeA.run(50)
|
||||
pause(200)
|
||||
motors.largeA.run(100)
|
||||
pause(200)
|
||||
})
|
||||
```
|
@ -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)
|
||||
})
|
||||
```
|
@ -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;
|
||||
|
@ -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();
|
||||
```
|
||||
|
@ -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)
|
||||
})
|
||||
```
|
||||
|
@ -3,7 +3,7 @@
|
||||
## Motion
|
||||
|
||||
```cards
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
motors.largeAB.tank(50, 50)
|
||||
motors.largeAB.steer(0, 50)
|
||||
motors.largeA.pauseUntilReady()
|
||||
|
@ -19,8 +19,8 @@ Reset the motor connected to port **A** and run it for for 2 seconds at a speed
|
||||
```blocks
|
||||
let motorAngle = 0;
|
||||
motors.largeA.reset()
|
||||
motors.largeA.setSpeed(45)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(45)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
motorAngle = motors.largeA.angle()
|
||||
```
|
||||
|
@ -15,12 +15,12 @@ See if the motor turns the same number of times for each of two count periods. R
|
||||
```blocks
|
||||
let tachoCount = 0;
|
||||
motors.largeA.reset()
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(10000)
|
||||
motors.largeA.run(50)
|
||||
pause(10000)
|
||||
tachoCount = motors.largeA.tacho()
|
||||
motors.largeA.clearCounts()
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(10000)
|
||||
motors.largeA.run(50)
|
||||
pause(10000)
|
||||
if (tachoCount == motors.largeA.tacho()) {
|
||||
brick.showString("Motor turns equal.", 1)
|
||||
} else {
|
||||
|
@ -13,13 +13,13 @@ The motor's speed is set back to `0` and the **tacho**, **angle**, and **speed**
|
||||
See what the angle count is when a motor is stopped. Then, try it again after a reset.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
brick.showString("Angle count:", 1)
|
||||
brick.showNumber(motors.largeA.angle(), 2)
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.reset()
|
||||
brick.showString("Angle count:", 4)
|
||||
brick.showNumber(motors.largeA.angle(), 5)
|
||||
|
@ -1,9 +1,9 @@
|
||||
# set Speed
|
||||
# run
|
||||
|
||||
Set the rotation speed of the motor as a percentage of maximum speed.
|
||||
|
||||
```sig
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
```
|
||||
|
||||
The speed setting is a pecentage of the motor's full speed. Full speed is the speed that the motor runs when the brick supplies maximum output voltage to the port.
|
||||
@ -19,7 +19,7 @@ If you use a number of milliseconds as movement units, then you don't need to in
|
||||
To run the motor for 500 milliseconds:
|
||||
|
||||
```block
|
||||
motors.largeA.setSpeed(50, 500)
|
||||
motors.largeA.run(50, 500)
|
||||
```
|
||||
|
||||
## ~
|
||||
@ -28,19 +28,19 @@ Here is how you use each different movement unit to run the motor for a fixed ro
|
||||
|
||||
```typescript
|
||||
// Run motor for 700 Milliseconds.
|
||||
motors.largeA.setSpeed(25, 700, MoveUnit.MilliSeconds);
|
||||
motors.largeA.run(25, 700, MoveUnit.MilliSeconds);
|
||||
|
||||
// Run motor for 700 Milliseconds again but no units specified.
|
||||
motors.largeA.setSpeed(25, 700);
|
||||
motors.largeA.run(25, 700);
|
||||
|
||||
// Run the motor for 45 seconds
|
||||
motors.largeA.setSpeed(50, 45, MoveUnit.Seconds);
|
||||
motors.largeA.run(50, 45, MoveUnit.Seconds);
|
||||
|
||||
// Turn the motor for 270 degrees
|
||||
motors.largeA.setSpeed(50, 270, MoveUnit.Degrees)
|
||||
motors.largeA.run(50, 270, MoveUnit.Degrees)
|
||||
|
||||
// Turn the motor at full speed for 9 full rotations
|
||||
motors.largeA.setSpeed(100, 9, MoveUnit.Rotations);
|
||||
motors.largeA.run(100, 9, MoveUnit.Rotations);
|
||||
```
|
||||
|
||||
## Parameters
|
||||
@ -56,7 +56,7 @@ motors.largeA.setSpeed(100, 9, MoveUnit.Rotations);
|
||||
Turning the motor in the opposite direction (reverse) is simple. Reverse is just a negative speed setting. To drive the motor in reverse at 25% speed:
|
||||
|
||||
```block
|
||||
motors.largeB.setSpeed(-25)
|
||||
motors.largeB.run(-25)
|
||||
```
|
||||
|
||||
## ~
|
||||
@ -68,8 +68,8 @@ motors.largeB.setSpeed(-25)
|
||||
Run the motor connected to port **A** continuously. Pause 20 seconds and then stop the motor.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(75)
|
||||
loops.pause(20000)
|
||||
motors.largeA.run(75)
|
||||
pause(20000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
@ -78,8 +78,8 @@ motors.largeA.stop()
|
||||
Run the motor connected to port **A** in reverse. Pause 5 seconds and then stop the motor.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(-60)
|
||||
loops.pause(5000)
|
||||
motors.largeA.run(-60)
|
||||
pause(5000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
@ -88,7 +88,7 @@ motors.largeA.stop()
|
||||
Run the motor connected to port **B** for 35 full rotations and then stop.
|
||||
|
||||
```blocks
|
||||
motors.largeB.setSpeed(50, 35, MoveUnit.Rotations)
|
||||
motors.largeB.run(50, 35, MoveUnit.Rotations)
|
||||
```
|
||||
|
||||
## See also
|
@ -19,8 +19,8 @@ Also, you can use the brake to do simple skid steering for your brick.
|
||||
Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and set the brake.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
motors.largeA.setBrake(true)
|
||||
```
|
||||
|
@ -17,13 +17,13 @@ You use a positive value (some number greater than `0`) to drive you motor in th
|
||||
Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and switch the direciton of rotation. Run the motor at a speed of `-30`. Watch and see if the motor turns in the same direction as before.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
loops.pause(2000)
|
||||
pause(2000)
|
||||
motors.largeA.setInverted(true)
|
||||
motors.largeA.setSpeed(-30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(-30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
|
@ -22,11 +22,11 @@ Turn off the speed regulation for the motor connected to port **A**.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setRegulated(false)
|
||||
motors.largeA.setSpeed(75)
|
||||
loops.pause(20000)
|
||||
motors.largeA.run(75)
|
||||
pause(20000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[set speed](/reference/motors/motor/set-speed), [stop](/reference/motors/motor/stop)
|
||||
[run](/reference/motors/motor/run), [stop](/reference/motors/motor/stop)
|
||||
|
@ -6,7 +6,7 @@ Get the current speed of motor rotation as a percentage of maximum speed.
|
||||
motors.largeA.speed()
|
||||
```
|
||||
|
||||
The actual speed of the motor is the same or very close to it's current speed setting when the motor is regulated. If not regulated, the actual speed can change from the set speed when a force, or load, is applied to it.
|
||||
The actual speed of the motor is the same or very close to it's current speed setting when the motor is regulated. If not regulated, the actual speed can change from the set point speed when a force, or load, is applied to it.
|
||||
|
||||
## Returns
|
||||
|
||||
@ -18,10 +18,10 @@ Turn speed regulation off and report the actual speed of the large motor in the
|
||||
|
||||
```blocks
|
||||
motors.largeA.setRegulated(false)
|
||||
motors.largeA.setSpeed(55)
|
||||
motors.largeA.run(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()
|
||||
|
@ -13,11 +13,11 @@ The motor stops but any motion caused from previously running the motor continue
|
||||
Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and wait for 2 seconds, then continue at a speed of `50`.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
loops.pause(2000)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
loops.pause(2000)
|
||||
motors.largeA.setSpeed(50)
|
||||
pause(2000)
|
||||
motors.largeA.run(50)
|
||||
```
|
||||
|
||||
## See also
|
||||
|
@ -33,12 +33,12 @@ A standard way to know how fast a motor is turning is by measuring its _revoluti
|
||||
Run the motor connected to port **A** at half speed for 5 seconds. Display the number of full rotations on the screen.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(5000)
|
||||
motors.largeA.run(50)
|
||||
pause(5000)
|
||||
motors.largeA.stop()
|
||||
brick.showString("Motor rotations:", 1)
|
||||
brick.showNumber(motors.largeA.tacho() / 360, 3)
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
```
|
||||
|
||||
## See also
|
||||
|
@ -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();
|
||||
```
|
||||
|
||||
|
@ -18,7 +18,7 @@ The speed setting is a pecentage of the motor's full speed. Full speed is the sp
|
||||
|
||||
If you use just the **speed** number, the motors run continously and won't stop unless you tell them to. You can also give a value for a certain amount of distance you want the motors to rotate for. The **value** can be an amount of time, a turn angle in degrees, or a number of full rotations.
|
||||
|
||||
If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [set speed](/reference/motors/motor/set-speed) shows how to use different movement units.
|
||||
If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [run](/reference/motors/motor/run) shows how to use different movement units.
|
||||
|
||||
## Parameters
|
||||
|
||||
@ -72,13 +72,13 @@ 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()
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[tank](/reference/motors/synced/tank), [set speed](/reference/motors/motor/set-speed)
|
||||
[tank](/reference/motors/synced/tank), [run](/reference/motors/motor/run)
|
@ -14,7 +14,7 @@ The speed setting is a pecentage of the motor's full speed. Full speed is the sp
|
||||
|
||||
If you use just the **speed** number, the motors run continously and won't stop unless you tell them to. You can also give a value for a certain amount of distance you want the motors to rotate for. The **value** can be an amount of time, a turn angle in degrees, or a number of full rotations.
|
||||
|
||||
If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [set speed](/reference/motors/motor/set-speed) shows how to use different movement units.
|
||||
If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [run](/reference/motors/motor/run) shows how to use different movement units.
|
||||
|
||||
## Parameters
|
||||
|
||||
@ -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,10 +72,10 @@ 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()
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[steer](/reference/motors/synced/steer), [set speed](/reference/motors/motor/set-speed)
|
||||
[steer](/reference/motors/synced/steer), [run](/reference/motors/motor/run)
|
34
libs/base/enums.d.ts
vendored
Normal file
34
libs/base/enums.d.ts
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// Auto-generated. Do not edit.
|
||||
|
||||
|
||||
declare const enum NumberFormat {
|
||||
Int8LE = 1,
|
||||
UInt8LE = 2,
|
||||
Int16LE = 3,
|
||||
UInt16LE = 4,
|
||||
Int32LE = 5,
|
||||
Int8BE = 6,
|
||||
UInt8BE = 7,
|
||||
Int16BE = 8,
|
||||
UInt16BE = 9,
|
||||
Int32BE = 10,
|
||||
|
||||
UInt32LE = 11,
|
||||
UInt32BE = 12,
|
||||
Float32LE = 13,
|
||||
Float64LE = 14,
|
||||
Float32BE = 15,
|
||||
Float64BE = 16,
|
||||
}
|
||||
|
||||
|
||||
declare const enum ValType {
|
||||
Undefined = 0,
|
||||
Boolean = 1,
|
||||
Number = 2,
|
||||
String = 3,
|
||||
Object = 4,
|
||||
Function = 5,
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
159
libs/base/shims.d.ts
vendored
Normal file
159
libs/base/shims.d.ts
vendored
Normal file
@ -0,0 +1,159 @@
|
||||
// Auto-generated. Do not edit.
|
||||
|
||||
|
||||
|
||||
//% indexerGet=BufferMethods::getByte indexerSet=BufferMethods::setByte
|
||||
declare interface Buffer {
|
||||
/**
|
||||
* Write a number in specified format in the buffer.
|
||||
*/
|
||||
//% shim=BufferMethods::setNumber
|
||||
setNumber(format: NumberFormat, offset: int32, value: number): void;
|
||||
|
||||
/**
|
||||
* Read a number in specified format from the buffer.
|
||||
*/
|
||||
//% shim=BufferMethods::getNumber
|
||||
getNumber(format: NumberFormat, offset: int32): number;
|
||||
|
||||
/** Returns the length of a Buffer object. */
|
||||
//% property shim=BufferMethods::length
|
||||
length: int32;
|
||||
|
||||
/**
|
||||
* Fill (a fragment) of the buffer with given value.
|
||||
*/
|
||||
//% offset.defl=0 length.defl=-1 shim=BufferMethods::fill
|
||||
fill(value: int32, offset?: int32, length?: int32): void;
|
||||
|
||||
/**
|
||||
* Return a copy of a fragment of a buffer.
|
||||
*/
|
||||
//% offset.defl=0 length.defl=-1 shim=BufferMethods::slice
|
||||
slice(offset?: int32, length?: int32): Buffer;
|
||||
|
||||
/**
|
||||
* Shift buffer left in place, with zero padding.
|
||||
* @param offset number of bytes to shift; use negative value to shift right
|
||||
* @param start start offset in buffer. Default is 0.
|
||||
* @param length number of elements in buffer. If negative, length is set as the buffer length minus
|
||||
* start. eg: -1
|
||||
*/
|
||||
//% start.defl=0 length.defl=-1 shim=BufferMethods::shift
|
||||
shift(offset: int32, start?: int32, length?: int32): void;
|
||||
|
||||
/**
|
||||
* Convert a buffer to its hexadecimal representation.
|
||||
*/
|
||||
//% shim=BufferMethods::toHex
|
||||
toHex(): string;
|
||||
|
||||
/**
|
||||
* Rotate buffer left in place.
|
||||
* @param offset number of bytes to shift; use negative value to shift right
|
||||
* @param start start offset in buffer. Default is 0.
|
||||
* @param length number of elements in buffer. If negative, length is set as the buffer length minus
|
||||
* start. eg: -1
|
||||
*/
|
||||
//% start.defl=0 length.defl=-1 shim=BufferMethods::rotate
|
||||
rotate(offset: int32, start?: int32, length?: int32): void;
|
||||
|
||||
/**
|
||||
* Write contents of `src` at `dstOffset` in current buffer.
|
||||
*/
|
||||
//% shim=BufferMethods::write
|
||||
write(dstOffset: int32, src: Buffer): void;
|
||||
}
|
||||
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 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 deprecated=true
|
||||
//% async block="pause %pause=timePicker|ms"
|
||||
//% blockId=device_pause_deprecated shim=loops::pause
|
||||
function pause(ms: int32): void;
|
||||
}
|
||||
declare namespace control {
|
||||
|
||||
/**
|
||||
* Gets the number of milliseconds elapsed since power on.
|
||||
*/
|
||||
//% help=control/millis weight=50
|
||||
//% blockId=control_running_time block="millis (ms)" shim=control::millis
|
||||
function millis(): int32;
|
||||
|
||||
/**
|
||||
* Run code when a registered event happens.
|
||||
* @param id the event compoent id
|
||||
* @param value the event value to match
|
||||
*/
|
||||
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src|with value %value"
|
||||
//% blockExternalInputs=1
|
||||
//% help="control/on-event" flags.defl=16 shim=control::onEvent
|
||||
function onEvent(src: int32, value: int32, handler: () => void, flags?: int32): void;
|
||||
|
||||
/**
|
||||
* Reset the device.
|
||||
*/
|
||||
//% weight=30 async help=control/reset blockGap=8
|
||||
//% blockId="control_reset" block="reset" shim=control::reset
|
||||
function reset(): void;
|
||||
|
||||
/**
|
||||
* Block the current fiber for the given microseconds
|
||||
* @param micros number of micro-seconds to wait. eg: 4
|
||||
*/
|
||||
//% help=control/wait-micros weight=29 async
|
||||
//% blockId="control_wait_us" block="wait (µs)%micros" shim=control::waitMicros
|
||||
function waitMicros(micros: int32): void;
|
||||
|
||||
/**
|
||||
* Run other code in the parallel.
|
||||
*/
|
||||
//% help=control/run-in-parallel handlerStatement=1
|
||||
//% blockId="control_run_in_parallel" block="run in parallel" blockGap=8 shim=control::runInParallel
|
||||
function runInParallel(a: () => void): void;
|
||||
|
||||
/**
|
||||
* Blocks the calling thread until the specified event is raised.
|
||||
*/
|
||||
//% help=control/wait-for-event async
|
||||
//% blockId=control_wait_for_event block="wait for event|from %src|with value %value" shim=control::waitForEvent
|
||||
function waitForEvent(src: int32, value: int32): void;
|
||||
|
||||
/**
|
||||
* Derive a unique, consistent serial number of this device from internal data.
|
||||
*/
|
||||
//% blockId="control_device_serial_number" block="device serial number" weight=9
|
||||
//% help=control/device-serial-number shim=control::deviceSerialNumber
|
||||
function deviceSerialNumber(): int32;
|
||||
}
|
||||
declare namespace serial {
|
||||
|
||||
/**
|
||||
* Write some text to the serial port.
|
||||
*/
|
||||
//% help=serial/write-string
|
||||
//% weight=87 blockHidden=true
|
||||
//% blockId=serial_writestring block="serial|write string %text" shim=serial::writeString
|
||||
function writeString(text: string): void;
|
||||
|
||||
/**
|
||||
* Send a buffer across the serial connection.
|
||||
*/
|
||||
//% help=serial/write-buffer weight=6 blockHidden=true
|
||||
//% blockId=serial_writebuffer block="serial|write buffer %buffer" shim=serial::writeBuffer
|
||||
function writeBuffer(buffer: Buffer): void;
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
@ -294,7 +294,7 @@ namespace sensors {
|
||||
}
|
||||
|
||||
// wait a bit
|
||||
loops.pause(50);
|
||||
pause(50);
|
||||
}
|
||||
|
||||
// apply tolerance
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Ambient Light
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.color1.ambientLight() > 20) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
} else {
|
||||
|
@ -1,7 +1,7 @@
|
||||
# color
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.color1.color() == ColorSensorColor.Green) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
} else {
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Reflected Light
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.color1.reflectedLight() > 20) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
} else {
|
||||
|
@ -248,7 +248,7 @@ namespace brick {
|
||||
|
||||
/**
|
||||
* Set lights.
|
||||
* @param pattern the lights pattern to use. eg: BrickLight.Orange
|
||||
* @param pattern the lights pattern to use. eg: StatusLight.Orange
|
||||
*/
|
||||
//% blockId=setLights block="set status light to %pattern"
|
||||
//% weight=100 group="Buttons"
|
||||
|
29
libs/core/enums.d.ts
vendored
Normal file
29
libs/core/enums.d.ts
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// Auto-generated. Do not edit.
|
||||
|
||||
|
||||
/**
|
||||
* Mode for lseek()
|
||||
*/
|
||||
|
||||
declare const enum SeekWhence {
|
||||
Set = 0,
|
||||
Current = 1,
|
||||
End = 2,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Drawing modes
|
||||
*/
|
||||
|
||||
declare const enum Draw {
|
||||
Normal = 0x00,
|
||||
Clear = 0x01,
|
||||
Xor = 0x02,
|
||||
Fill = 0x04,
|
||||
Transparent = 0x08,
|
||||
Double = 0x10,
|
||||
Quad = 0x20,
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,17 +134,17 @@ namespace motors {
|
||||
protected _brake: boolean;
|
||||
private _initialized: boolean;
|
||||
private _init: () => void;
|
||||
private _setSpeed: (speed: number) => void;
|
||||
private _run: (speed: number) => void;
|
||||
private _move: (steps: boolean, stepsOrTime: number, speed: number) => void;
|
||||
|
||||
constructor(port: Output, init: () => void, setSpeed: (speed: number) => void, move: (steps: boolean, stepsOrTime: number, speed: number) => void) {
|
||||
constructor(port: Output, init: () => void, run: (speed: number) => void, move: (steps: boolean, stepsOrTime: number, speed: number) => void) {
|
||||
super();
|
||||
this._port = port;
|
||||
this._portName = outputToName(this._port);
|
||||
this._brake = false;
|
||||
this._initialized = false;
|
||||
this._init = init;
|
||||
this._setSpeed = setSpeed;
|
||||
this._run = run;
|
||||
this._move = move;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,17 +218,17 @@ namespace motors {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the motor speed for limited time or distance.
|
||||
* Runs the motor at a given speed for limited time or distance.
|
||||
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
|
||||
* @param value (optional) measured distance or rotation
|
||||
* @param unit (optional) unit of the value
|
||||
*/
|
||||
//% blockId=motorSetSpeed block="set %motor speed to %speed=motorSpeedPicker|\\%||for %value %unit"
|
||||
//% blockId=motorRun block="run %motor at %speed=motorSpeedPicker|\\%||for %value %unit"
|
||||
//% weight=100 blockGap=8
|
||||
//% group="Move"
|
||||
//% expandableArgumentMode=toggle
|
||||
//% help=motors/motor/set-speed
|
||||
setSpeed(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
||||
//% help=motors/motor/run
|
||||
run(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
||||
this.init();
|
||||
speed = Math.clamp(-100, 100, speed >> 0);
|
||||
// stop if speed is 0
|
||||
@ -238,7 +238,7 @@ namespace motors {
|
||||
}
|
||||
// special: 0 is infinity
|
||||
if (value == 0) {
|
||||
this._setSpeed(speed);
|
||||
this._run(speed);
|
||||
return;
|
||||
}
|
||||
// timed motor moves
|
||||
|
144
libs/core/shims.d.ts
vendored
Normal file
144
libs/core/shims.d.ts
vendored
Normal file
@ -0,0 +1,144 @@
|
||||
// Auto-generated. Do not edit.
|
||||
declare namespace control {
|
||||
|
||||
/** Create new file mapping in memory */
|
||||
//% shim=control::mmap
|
||||
function mmap(filename: string, size: int32, offset: int32): MMap;
|
||||
}
|
||||
|
||||
|
||||
declare interface MMap {
|
||||
/**
|
||||
* Write a number in specified format in the buffer.
|
||||
*/
|
||||
//% shim=MMapMethods::setNumber
|
||||
setNumber(format: NumberFormat, offset: int32, value: number): void;
|
||||
|
||||
/**
|
||||
* Read a number in specified format from the buffer.
|
||||
*/
|
||||
//% shim=MMapMethods::getNumber
|
||||
getNumber(format: NumberFormat, offset: int32): number;
|
||||
|
||||
/**
|
||||
* Read a range of bytes into a buffer.
|
||||
*/
|
||||
//% offset.defl=0 length.defl=-1 shim=MMapMethods::slice
|
||||
slice(offset?: int32, length?: int32): Buffer;
|
||||
|
||||
/** Returns the length of a Buffer object. */
|
||||
//% property shim=MMapMethods::length
|
||||
length: int32;
|
||||
|
||||
/** Perform ioctl(2) on the underlaying file */
|
||||
//% shim=MMapMethods::ioctl
|
||||
ioctl(id: uint32, data: Buffer): int32;
|
||||
|
||||
/** Perform write(2) on the underlaying file */
|
||||
//% shim=MMapMethods::write
|
||||
write(data: Buffer): int32;
|
||||
|
||||
/** Perform read(2) on the underlaying file */
|
||||
//% shim=MMapMethods::read
|
||||
read(data: Buffer): int32;
|
||||
|
||||
/** Set pointer on the underlaying file. */
|
||||
//% shim=MMapMethods::lseek
|
||||
lseek(offset: int32, whence: SeekWhence): int32;
|
||||
}
|
||||
declare namespace control {
|
||||
|
||||
/**
|
||||
* Announce that an event happened to registered handlers.
|
||||
* @param src ID of the Component that generated the event
|
||||
* @param value Component specific code indicating the cause of the event.
|
||||
* @param mode optional definition of how the event should be processed after construction.
|
||||
*/
|
||||
//% weight=21 blockGap=12 blockId="control_raise_event"
|
||||
//% block="raise event|from %src|with value %value" blockExternalInputs=1 shim=control::raiseEvent
|
||||
function raiseEvent(src: int32, value: int32): void;
|
||||
|
||||
/**
|
||||
* Allocates the next user notification event
|
||||
*/
|
||||
//% help=control/allocate-notify-event shim=control::allocateNotifyEvent
|
||||
function allocateNotifyEvent(): int32;
|
||||
|
||||
/** Write data to DMESG debugging buffer. */
|
||||
//% shim=control::dmesg
|
||||
function dmesg(s: string): void;
|
||||
}
|
||||
declare namespace serial {
|
||||
|
||||
/** Send DMESG debug buffer over serial. */
|
||||
//% shim=serial::writeDmesg
|
||||
function writeDmesg(): void;
|
||||
}
|
||||
declare namespace screen {
|
||||
|
||||
/** Decompresses a 1-bit gray scale PNG image to image format. */
|
||||
//% shim=screen::unpackPNG
|
||||
function unpackPNG(png: Buffer): Image;
|
||||
}
|
||||
declare namespace screen {
|
||||
|
||||
/** Clear screen and reset font to normal. */
|
||||
//% shim=screen::clear
|
||||
function clear(): void;
|
||||
|
||||
/** Makes an image bound to a buffer. */
|
||||
//% shim=screen::imageOf
|
||||
function imageOf(buf: Buffer): Image;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//% fixedInstances
|
||||
declare interface Image {
|
||||
/** Returns the underlaying Buffer object. */
|
||||
//% property shim=ImageMethods::buffer
|
||||
buffer: Buffer;
|
||||
|
||||
/** Returns the width of an image. */
|
||||
//% property shim=ImageMethods::width
|
||||
width: int32;
|
||||
|
||||
/** Returns the height of an image. */
|
||||
//% property shim=ImageMethods::height
|
||||
height: int32;
|
||||
|
||||
/** Double size of an image. */
|
||||
//% shim=ImageMethods::doubled
|
||||
doubled(): Image;
|
||||
|
||||
/** Draw an image on the screen. */
|
||||
//% shim=ImageMethods::draw
|
||||
draw(x: int32, y: int32, mode: Draw): void;
|
||||
}
|
||||
declare namespace output {
|
||||
|
||||
/**
|
||||
* Create a new zero-initialized buffer.
|
||||
* @param size number of bytes in the buffer
|
||||
*/
|
||||
//% shim=output::createBuffer
|
||||
function createBuffer(size: int32): Buffer;
|
||||
}
|
||||
declare namespace motors {
|
||||
|
||||
/**
|
||||
* Mark a motor as used
|
||||
*/
|
||||
//% shim=motors::__motorUsed
|
||||
function __motorUsed(port: int32, large: boolean): void;
|
||||
}
|
||||
declare namespace sensors {
|
||||
|
||||
/**
|
||||
* Mark a sensor as used
|
||||
*/
|
||||
//% shim=sensors::__sensorUsed
|
||||
function __sensorUsed(port: int32, type: int32): void;
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
@ -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)
|
||||
})
|
||||
*/
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ namespace brick {
|
||||
brick.setStatusLight(this.light);
|
||||
brick.showImage(this.image);
|
||||
music.playSoundEffectUntilDone(this.sound);
|
||||
loops.pause(20);
|
||||
pause(20);
|
||||
}
|
||||
}
|
||||
|
||||
|
56
libs/music/shims.d.ts
vendored
Normal file
56
libs/music/shims.d.ts
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
// Auto-generated. Do not edit.
|
||||
declare namespace music {
|
||||
|
||||
/**
|
||||
* Set the output volume of the sound synthesizer.
|
||||
* @param volume the volume 0...100, eg: 50
|
||||
*/
|
||||
//% weight=96
|
||||
//% blockId=synth_set_volume block="set volume %volume"
|
||||
//% parts="speaker" blockGap=8
|
||||
//% volume.min=0 volume.max=100
|
||||
//% help=music/set-volume
|
||||
//% weight=1 shim=music::setVolume
|
||||
function setVolume(volume: int32): void;
|
||||
|
||||
/**
|
||||
* Play a tone through the speaker for some amount of time.
|
||||
* @param frequency pitch of the tone to play in Hertz (Hz)
|
||||
* @param ms tone duration in milliseconds (ms)
|
||||
*/
|
||||
//% help=music/play-tone
|
||||
//% blockId=music_play_note block="play tone|at %note=device_note|for %duration=device_beat"
|
||||
//% parts="headphone" async
|
||||
//% blockNamespace=music
|
||||
//% weight=76 blockGap=8 shim=music::playTone
|
||||
function playTone(frequency: int32, ms: int32): void;
|
||||
|
||||
/**
|
||||
* Play a tone through the speaker for some amount of time.
|
||||
*/
|
||||
//% help=music/stop-all-sounds
|
||||
//% blockId=music_stop_all_sounds block="stop all sounds"
|
||||
//% parts="headphone"
|
||||
//% blockNamespace=music
|
||||
//% weight=97 shim=music::stopAllSounds
|
||||
function stopAllSounds(): void;
|
||||
|
||||
/** Makes a sound bound to a buffer in WAV format. */
|
||||
//% shim=music::fromWAV
|
||||
function fromWAV(buf: Buffer): Sound;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//% fixedInstances
|
||||
declare interface Sound {
|
||||
/** Returns the underlaying Buffer object. */
|
||||
//% property shim=SoundMethods::buffer
|
||||
buffer: Buffer;
|
||||
|
||||
/** Play sound. */
|
||||
//% promise shim=SoundMethods::play
|
||||
play(): void;
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
@ -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)
|
||||
|
17
libs/storage/shims.d.ts
vendored
Normal file
17
libs/storage/shims.d.ts
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Auto-generated. Do not edit.
|
||||
declare namespace storage {
|
||||
|
||||
/** Will be moved. */
|
||||
//% shim=storage::__stringToBuffer
|
||||
function __stringToBuffer(s: string): Buffer;
|
||||
|
||||
/** Will be moved. */
|
||||
//% shim=storage::__bufferToString
|
||||
function __bufferToString(s: Buffer): string;
|
||||
|
||||
/** Create named directory. */
|
||||
//% shim=storage::__mkdir
|
||||
function __mkdir(filename: string): void;
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
@ -7,9 +7,9 @@ A unit test framework
|
||||
Tests are registered as event handlers. They will automatically run once ``on start`` is finished.
|
||||
|
||||
```blocks
|
||||
tests.test("lgB set speed 10", () => {
|
||||
motors.largeB.setSpeed(10);
|
||||
loops.pause(100)
|
||||
tests.test("lgB run 10", () => {
|
||||
motors.largeB.run(10);
|
||||
pause(100)
|
||||
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`.
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.touch1.isPressed()) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
} 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`.
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
forever(function () {
|
||||
if (sensors.touch1.wasPressed()) {
|
||||
brick.setStatusLight(StatusLight.Green)
|
||||
} else {
|
||||
brick.setStatusLight(StatusLight.Orange)
|
||||
}
|
||||
loops.pause(500)
|
||||
pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
|
128
package-lock.json
generated
128
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.0.100",
|
||||
"version": "0.0.103",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -3274,19 +3274,19 @@
|
||||
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
|
||||
},
|
||||
"pxt-common-packages": {
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/pxt-common-packages/-/pxt-common-packages-0.19.1.tgz",
|
||||
"integrity": "sha512-I+4nnq/QaGTMyZctUXBGBAB+I09a4VfaxShPtjZjx7oS9dNYg+95yUHl/izPZhmCq4W8pcJ2D7x4//E7nXw5Iw==",
|
||||
"version": "0.19.4",
|
||||
"resolved": "https://registry.npmjs.org/pxt-common-packages/-/pxt-common-packages-0.19.4.tgz",
|
||||
"integrity": "sha512-sAccQrTh+LNuuDuQlkeuGaRu99+7iORfiREJV7eemqzr5yuspgA9aLif0FYFIPas37RD8Uoz+n36RxgsKZoLJg==",
|
||||
"requires": {
|
||||
"autoprefixer": "6.7.7",
|
||||
"pxt-core": "3.4.1",
|
||||
"pxt-core": "3.4.3",
|
||||
"rtlcss": "2.2.1"
|
||||
}
|
||||
},
|
||||
"pxt-core": {
|
||||
"version": "3.4.1",
|
||||
"resolved": "https://registry.npmjs.org/pxt-core/-/pxt-core-3.4.1.tgz",
|
||||
"integrity": "sha512-xP386XsMFejInYwtzz7FWuE2hbA0gjtxOZjFzxUb8RfZKIDLjoHSod/q/TUKcmWXU0ytepuTtNbC7a4Hp8Ndmw==",
|
||||
"version": "3.4.3",
|
||||
"resolved": "https://registry.npmjs.org/pxt-core/-/pxt-core-3.4.3.tgz",
|
||||
"integrity": "sha512-zsBf5/pf9B5vS4THqTQLOFodi+o0GtX2npvT3efF6Cql29dXtzVYKUAxSclzGCtNljI34dC++CLaaPfYfzMOnQ==",
|
||||
"requires": {
|
||||
"bluebird": "3.5.1",
|
||||
"browserify": "13.3.0",
|
||||
@ -3315,75 +3315,28 @@
|
||||
}
|
||||
},
|
||||
"chalk": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz",
|
||||
"integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==",
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.1.tgz",
|
||||
"integrity": "sha512-QUU4ofkDoMIVO7hcx1iPTISs88wsO8jA92RQIm4JAwZvFGGAV2hSAA1NX7oVj2Ej2Q6NDTcRDjPTFrMCRZoJ6g==",
|
||||
"requires": {
|
||||
"ansi-styles": "3.2.0",
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"supports-color": "4.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"supports-color": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz",
|
||||
"integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=",
|
||||
"requires": {
|
||||
"has-flag": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"commander": {
|
||||
"version": "2.14.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz",
|
||||
"integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw==",
|
||||
"optional": true
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
"supports-color": "5.2.0"
|
||||
}
|
||||
},
|
||||
"has-flag": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz",
|
||||
"integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE="
|
||||
},
|
||||
"nan": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz",
|
||||
"integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=",
|
||||
"optional": true
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
|
||||
},
|
||||
"postcss": {
|
||||
"version": "6.0.17",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-6.0.17.tgz",
|
||||
"integrity": "sha512-Bl1nybsSzWYbP8O4gAVD8JIjZIul9hLNOPTGBIlVmZNUnNAGL+W0cpYWzVwfImZOwumct4c1SDvSbncVWKtXUw==",
|
||||
"requires": {
|
||||
"chalk": "2.3.0",
|
||||
"chalk": "2.3.1",
|
||||
"source-map": "0.6.1",
|
||||
"supports-color": "5.1.0"
|
||||
}
|
||||
},
|
||||
"serialport": {
|
||||
"version": "6.0.5",
|
||||
"resolved": "https://registry.npmjs.org/serialport/-/serialport-6.0.5.tgz",
|
||||
"integrity": "sha512-ZYof3a9m08LTgDU82TFAbjRADIZ1GQTrqXY6JYnCHk8NFv0bEU0qL/MMX8F4wB9oNVbtkaYYeJc6E+gl2bSXpw==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"bindings": "1.3.0",
|
||||
"commander": "2.14.1",
|
||||
"debug": "3.1.0",
|
||||
"nan": "2.8.0",
|
||||
"prebuild-install": "2.4.1",
|
||||
"promirepl": "1.0.1",
|
||||
"prompt-list": "3.1.2",
|
||||
"safe-buffer": "5.1.1"
|
||||
"supports-color": "5.2.0"
|
||||
}
|
||||
},
|
||||
"source-map": {
|
||||
@ -3392,11 +3345,11 @@
|
||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.1.0.tgz",
|
||||
"integrity": "sha512-Ry0AwkoKjDpVKK4sV4h6o3UJmNRbjYm2uXhwfj3J56lMVdvnUNqzQVRztOOMGQ++w1K/TjNDFvpJk0F/LoeBCQ==",
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.2.0.tgz",
|
||||
"integrity": "sha512-F39vS48la4YvTZUPVeTqsjsFNrvcMwrV3RLZINsmHo+7djCvuUzSIeXOnZ5hmjef4bajL1dNccN+tg5XAliO5Q==",
|
||||
"requires": {
|
||||
"has-flag": "2.0.0"
|
||||
"has-flag": "3.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3771,6 +3724,45 @@
|
||||
"integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg==",
|
||||
"optional": true
|
||||
},
|
||||
"serialport": {
|
||||
"version": "6.0.5",
|
||||
"resolved": "https://registry.npmjs.org/serialport/-/serialport-6.0.5.tgz",
|
||||
"integrity": "sha512-ZYof3a9m08LTgDU82TFAbjRADIZ1GQTrqXY6JYnCHk8NFv0bEU0qL/MMX8F4wB9oNVbtkaYYeJc6E+gl2bSXpw==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"bindings": "1.3.0",
|
||||
"commander": "2.14.1",
|
||||
"debug": "3.1.0",
|
||||
"nan": "2.8.0",
|
||||
"prebuild-install": "2.4.1",
|
||||
"promirepl": "1.0.1",
|
||||
"prompt-list": "3.1.2",
|
||||
"safe-buffer": "5.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": {
|
||||
"version": "2.14.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.14.1.tgz",
|
||||
"integrity": "sha512-+YR16o3rK53SmWHU3rEM3tPAh2rwb1yPcQX5irVn7mb0gXbwuCCrnkbV5+PBfETdfg1vui07nM6PCG1zndcjQw==",
|
||||
"optional": true
|
||||
},
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"nan": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz",
|
||||
"integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=",
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"set-blocking": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.0.100",
|
||||
"version": "0.0.103",
|
||||
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
|
||||
"private": true,
|
||||
"keywords": [
|
||||
@ -45,8 +45,8 @@
|
||||
"webfonts-generator": "^0.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-common-packages": "0.19.1",
|
||||
"pxt-core": "3.4.3"
|
||||
"pxt-common-packages": "0.19.5",
|
||||
"pxt-core": "3.4.5"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||
|
@ -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)
|
||||
})
|
@ -1,42 +1,42 @@
|
||||
// add tests package
|
||||
tests.test("lgB set speed 10", () => {
|
||||
motors.largeB.setSpeed(10);
|
||||
loops.pause(500)
|
||||
tests.test("lgB run 10", () => {
|
||||
motors.largeB.run(10);
|
||||
pause(500)
|
||||
tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
|
||||
});
|
||||
tests.test("lgB set speed 25 (reversed)", () => {
|
||||
tests.test("lgB run 25 (reversed)", () => {
|
||||
motors.largeB.setInverted(true)
|
||||
motors.largeB.setSpeed(25)
|
||||
loops.pause(500)
|
||||
motors.largeB.run(25)
|
||||
pause(500)
|
||||
tests.assertClose("speedB", -25, motors.largeB.speed(), 2)
|
||||
});
|
||||
tests.test("lgBC set speed 5", () => {
|
||||
motors.largeBC.setSpeed(5)
|
||||
loops.pause(500)
|
||||
tests.test("lgBC run 5", () => {
|
||||
motors.largeBC.run(5)
|
||||
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)
|
||||
});
|
||||
|
Reference in New Issue
Block a user