Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
653d8f6f5c | |||
ac0a9f0710 | |||
2cce2a39b8 |
251
docs/labview.md
Normal file
@ -0,0 +1,251 @@
|
||||
# Coding in MakeCode
|
||||
|
||||
This guide is intended for users who are used to the LabView LEGO Minstorms editor.
|
||||
|
||||
## Snap the blocks
|
||||
|
||||
Just like LabView, blocks can be dragged from the cabinet and snapped together
|
||||
to create a sequence of program instructions.
|
||||
|
||||
The program below **starts**, turns on motor A, waits a second and stop motor A.
|
||||
|
||||

|
||||
|
||||
The blocks are similar: they snap on the ``||on start||`` block then latch to each other vertically.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(1000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
All block programs can be converted to JavaScript and edited from there as well.
|
||||
|
||||
```typescript
|
||||
motors.largeA.setSpeed(50)
|
||||
loops.pause(1000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
## Download to the EV3
|
||||
|
||||
The MakeCode editor provides a simulator to try out the code in your browser. It restarts automatically after you make a code change. Once you are ready to transfer it to the @boardname@, click the ``||Download||`` button and follow the instructions.
|
||||
|
||||
## Single motors
|
||||
|
||||
The program below controls a large motor on port A in a variety of ways: setting the speed,
|
||||
setting the speed for a given time, angle or number of rotations.
|
||||
|
||||

|
||||
|
||||
```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.stop();
|
||||
```
|
||||
|
||||
## Steering
|
||||
|
||||
The **steering** blocks allow to synchronize two motors at a precise rate. They can also specify the duration, angle or number of rotations.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeBC.steer(0, 50);
|
||||
motors.largeBC.steer(0, 50, 1000, MoveUnit.MilliSeconds);
|
||||
motors.largeBC.steer(0, 50, 360, MoveUnit.Degrees);
|
||||
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations);
|
||||
motors.largeBC.stop();
|
||||
```
|
||||
|
||||
## Tank
|
||||
|
||||
The **tank** blocks control the speed of two motors, typically from a differential drive robot. They can also specify the duration, angle or number of rotations.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeBC.tank(50, 50);
|
||||
motors.largeBC.tank(50, 50, 1000, MoveUnit.MilliSeconds);
|
||||
motors.largeBC.tank(50, 50, 360, MoveUnit.Degrees);
|
||||
motors.largeBC.tank(50, 50, 1, MoveUnit.Rotations);
|
||||
motors.largeBC.stop();
|
||||
```
|
||||
|
||||
## Coasting and braking
|
||||
|
||||
By default, all motors coast when the move command is done. You can change this behavior with the `set brake`` block.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeD.setBrake(true);
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations)
|
||||
```
|
||||
|
||||
## Inverting and regulating motors
|
||||
|
||||
Sometime you need to invert the direction of a motor. Use the ``set invert`` block.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeA.setInverted(true);
|
||||
```
|
||||
|
||||
By default, the speed of motors is regulated. This means that if your robot goes up a hill,
|
||||
the regulator will adjust the power to match the desired speed. You can disable this feature
|
||||
using ``set regulated``.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeA.setRegulated(false);
|
||||
```
|
||||
|
||||
## Brick
|
||||
|
||||
The brick category contains a number of blocks to display graphics on the brick screen.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
brick.clearScreen()
|
||||
brick.showImage(images.expressionsWink)
|
||||
```
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
brick.setStatusLight(StatusLight.Off);
|
||||
brick.setStatusLight(StatusLight.Red);
|
||||
brick.setStatusLight(StatusLight.OrangePulse);
|
||||
```
|
||||
|
||||
## Waiting (pausing)
|
||||
|
||||
It is quite common to wait for a sensor state, such as a touch button pressed.
|
||||
The ``pause until`` blocks provide a variety of ways to acheive this.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
loops.pause(1000)
|
||||
motors.largeD.stop();
|
||||
```
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeD.stop();
|
||||
```
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
|
||||
motors.largeD.stop();
|
||||
```
|
||||
|
||||
You can also use the ``pause until`` block to wait on any boolean expression.
|
||||
The runtime will evaluate this expression until it becomes true.
|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
pauseUntil(() => sensors.touch1.isPressed())
|
||||
motors.largeD.stop()
|
||||
```
|
||||
|
||||
## Loops
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(() => {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
for(let i = 0; i < 10; i++) {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
}
|
||||
let k = 0;
|
||||
while(k < 10) {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
k++;
|
||||
}
|
||||
```
|
||||
|
||||
## Variables
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
let light = 0;
|
||||
loops.forever(function () {
|
||||
light = sensors.color3.light(LightIntensityMode.Reflected);
|
||||
motors.largeD.setSpeed(light)
|
||||
})
|
||||
```
|
||||
|
||||
## Concurrent loops
|
||||
|
||||
You can spin up multiple ``forever`` loops that will run at the same time.
|
||||
Only one code is running at the time, but each loop iteration will interleave.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(() => {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
})
|
||||
loops.forever(() => {
|
||||
brick.showImage(images.eyesMiddleRight)
|
||||
loops.pause(1000)
|
||||
brick.showImage(images.eyesMiddleLeft)
|
||||
loops.pause(1000)
|
||||
})
|
||||
```
|
||||
|
||||
## Conditional
|
||||
|
||||
The ``if`` block allow to run different code based on a boolean condition.
|
||||
This is similar to the switch block.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(function() {
|
||||
if(sensors.touch1.isPressed()) {
|
||||
motors.largeD.setSpeed(50)
|
||||
} else {
|
||||
motors.largeD.stop()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## Random
|
||||
|
||||
The ``random range`` blocks returns number between two bounds.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
motors.largeBC.steer(Math.randomRange(-5, 5), 50)
|
||||
loops.pause(100)
|
||||
})
|
||||
```
|
BIN
docs/static/labview/brake.png
vendored
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
docs/static/labview/brickimage.png
vendored
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
docs/static/labview/brickstatuslight.png
vendored
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
docs/static/labview/ife.png
vendored
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
docs/static/labview/invertmotor.png
vendored
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
docs/static/labview/lighttospeed.png
vendored
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
docs/static/labview/loopinfinite.PNG
vendored
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
docs/static/labview/motors.png
vendored
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
docs/static/labview/multipleloops.png
vendored
Normal file
After Width: | Height: | Size: 52 KiB |
BIN
docs/static/labview/pausefordistance.png
vendored
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
docs/static/labview/pausefortime.png
vendored
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
docs/static/labview/pausefortouch.png
vendored
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
docs/static/labview/random.png
vendored
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
docs/static/labview/sequencing.png
vendored
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
docs/static/labview/speedoflight.png
vendored
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
docs/static/labview/speedoflightvar.png
vendored
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
docs/static/labview/steer.png
vendored
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
docs/static/labview/tank.png
vendored
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
docs/static/labview/unregulatedmotor.png
vendored
Normal file
After Width: | Height: | Size: 9.8 KiB |
BIN
docs/static/labview/while.png
vendored
Normal file
After Width: | Height: | Size: 26 KiB |
@ -12,7 +12,7 @@ namespace brick {
|
||||
namespace sensors {
|
||||
}
|
||||
|
||||
//% color="#A5CA18" weight=90 icon="\uf10d"
|
||||
//% color="#00852B" weight=90 icon="\uf10d"
|
||||
//% groups='["Move", "Counters"]'
|
||||
//% labelLineWidth=50
|
||||
namespace motors {
|
||||
|
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.0.92",
|
||||
"version": "0.0.93",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.0.92",
|
||||
"version": "0.0.93",
|
||||
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
|
||||
"private": true,
|
||||
"keywords": [
|
||||
|
@ -137,7 +137,7 @@
|
||||
"blockColors": {
|
||||
"loops": "#58AB41",
|
||||
"logic": "#1E5AA8",
|
||||
"math": "#9DC3F7",
|
||||
"math": "#7396C8",
|
||||
"variables": "#B40000",
|
||||
"text": "#FCAC00",
|
||||
"advanced": "#969696",
|
||||
|