fixing a bunch of snippets

This commit is contained in:
Peli de Halleux 2018-01-18 16:43:16 -08:00
parent a60427e2cf
commit db4ed6daf3
20 changed files with 93 additions and 75 deletions

View File

@ -1,6 +1,40 @@
# @extends # @extends
## Lessons #Lessons ## Projects #projects
* [Maker](/maker)
* [Sound Machine](/maker/sound-machine)
* [Sound of Color](/maker/sound-of-color)
* [Security Gadget](/maker/security-gadget)
* [Intruder detector](/maker/intruder-detector)
* [Puppet](/maker/puppet)
* [Coding](/coding)
* [Three Point Turn 1](/coding/three-point-turn-1)
* [Three Point Turn 2](/coding/three-point-turn-2)
* [Three Point Turn 3](/coding/three-point-turn-3)
* [Reversing the robot 1](/coding/reversing-the-robot-1)
* [Reversing the robot 2](/coding/reversing-the-robot-2)
* [Reversing the robot 3](/coding/reversing-the-robot-3)
* [Light the way 1](/coding/light-the-way-1)
* [Light the way 2](/coding/light-the-way-2)
* [Light the way 3](/coding/light-the-way-3)
* [Traffic Lights 1](/coding/traffic-lights-1)
* [Traffic Lights 2](/coding/traffic-lights-2)
* [Traffic Lights 3](/coding/traffic-lights-3)
* [Reverse Beeper 1](/coding/reverse-beeper-1)
* [Reverse Beeper 2](/coding/reverse-beeper-2)
* [Reverse Beeper 3](/coding/reverse-beeper-3)
* [Ignition 1](/coding/ignition-1)
* [Ignition 2](/coding/ignition-2)
* [Ignition 3](/coding/ignition-3)
* [Cruise Control 1](/coding/cruise-control-1)
* [Cruise Control 2](/coding/cruise-control-2)
* [Cruise Control 3](/coding/cruise-control-3)
* [Roaming 1](/coding/roaming-1)
* [Roaming 2](/coding/roaming-2)
## Lessons #lessons
* [Lessons](/lessons) * [Lessons](/lessons)
* [Make it move](/lessons/make-it-move) * [Make it move](/lessons/make-it-move)

View File

@ -6,14 +6,14 @@ Welcome to the **Microsoft MakeCode** editor for the **@boardname@**!
You can program the @boardname@ using [Blocks](/blocks) or [JavaScript](/javascript) in your web browser: You can program the @boardname@ using [Blocks](/blocks) or [JavaScript](/javascript) in your web browser:
```block ```blocks
input.buttonA.onEvent(ButtonEvent.Click, () => { brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
light.showRing(`blue blue blue blue blue blue blue blue blue blue`) motors.largeA.setSpeed(50)
}) })
``` ```
```typescript ```typescript
input.buttonA.onEvent(ButtonEvent.Click, () => { brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
light.showRing(`blue blue blue blue blue blue blue blue blue blue`) motors.largeA.setSpeed(50)
}) })
``` ```
@ -22,10 +22,10 @@ The editor work in [most modern browsers](/browsers), work [offline](/offline) o
## [Compile and Flash: Your Program!](/device/usb) ## [Compile and Flash: Your Program!](/device/usb)
When you have your code ready, you connect your @boardname@ to a computer via a USB cable When you have your code ready, you connect your @boardname@ to a computer via a USB cable
**then press the reset button** so it appears as a mounted drive (named **CPLAYBOOT**). so it appears as a mounted drive (named **EV3**).
Compilation to machine code from [Blocks](/blocks) or [JavaScript](/javascript) happens in the browser. You save the binary Compilation to machine code from [Blocks](/blocks) or [JavaScript](/javascript) happens in the browser. You save the binary
program to a **.uf2** file, which you then copy to the **CPLAYBOOT** drive, which flashes the device with the new program. program to a **.uf2** file, which you then copy to the **EV3** drive, which flashes the device with the new program.
## Simulator: Test Your Code ## Simulator: Test Your Code
@ -33,11 +33,7 @@ You can run your code using the micro:bit simulator, all within the confines of
The simulator has support for the LED screen, buttons, as well as compass, accelerometer, and digital I/O pins. The simulator has support for the LED screen, buttons, as well as compass, accelerometer, and digital I/O pins.
```sim ```sim
loops.forever(() => { brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
light.pixels.showAnimation(light.animation(LightAnimation.Rainbow), 1000) motors.largeA.setSpeed(50)
}) })
``` ```
```package
light
```

View File

@ -3,10 +3,10 @@
```blocks ```blocks
brick.buttonEnter.onEvent(ButtonEvent.Click, function () { brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
motors.largeBC.setSpeed(50) motors.largeBC.setSpeed(50)
sensors.touchSensor1.pauseUntil(TouchSensorEvent.Pressed) sensors.touch1.pauseUntil(TouchSensorEvent.Pressed)
motors.largeBC.setSpeed(0) motors.largeBC.setSpeed(0)
loops.pause(1000) loops.pause(1000)
brick.setLight(LightsPattern.OrangeFlash) brick.setLight(BrickLight.OrangeFlash)
motors.largeBC.setSpeed(-50) motors.largeBC.setSpeed(-50)
loops.pause(2000) loops.pause(2000)
motors.largeBC.setSpeed(0) motors.largeBC.setSpeed(0)

View File

@ -2,12 +2,12 @@
```blocks ```blocks
brick.buttonEnter.onEvent(ButtonEvent.Click, function () { brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
sensors.touchSensor1.pauseUntil(TouchSensorEvent.Pressed) sensors.touch1.pauseUntil(TouchSensorEvent.Pressed)
motors.largeBC.setSpeed(50) motors.largeBC.setSpeed(50)
sensors.touchSensor2.pauseUntil(TouchSensorEvent.Pressed) sensors.touch2.pauseUntil(TouchSensorEvent.Pressed)
motors.largeBC.setSpeed(0) motors.largeBC.setSpeed(0)
loops.pause(1000) loops.pause(1000)
brick.setLight(LightsPattern.OrangeFlash) brick.setLight(BrickLight.OrangeFlash)
motors.largeBC.setSpeed(-50) motors.largeBC.setSpeed(-50)
loops.pause(2000) loops.pause(2000)
motors.largeBC.setSpeed(0) motors.largeBC.setSpeed(0)

View File

@ -3,14 +3,14 @@
```blocks ```blocks
brick.buttonEnter.onEvent(ButtonEvent.Click, function () { brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
brick.showImage(images.eyesSleeping) brick.showImage(images.eyesSleeping)
sensors.touchSensor1.pauseUntil(TouchSensorEvent.Pressed) sensors.touch1.pauseUntil(TouchSensorEvent.Pressed)
brick.showImage(images.eyesNeutral) brick.showImage(images.eyesNeutral)
motors.largeBC.setSpeed(50) motors.largeBC.setSpeed(50)
sensors.touchSensor2.pauseUntil(TouchSensorEvent.Pressed) sensors.touch2.pauseUntil(TouchSensorEvent.Pressed)
brick.showImage(images.eyesTiredMiddle) brick.showImage(images.eyesTiredMiddle)
motors.largeBC.setSpeed(0) motors.largeBC.setSpeed(0)
loops.pause(1000) loops.pause(1000)
brick.setLight(LightsPattern.OrangeFlash) brick.setLight(BrickLight.OrangeFlash)
brick.showImage(images.eyesDizzy) brick.showImage(images.eyesDizzy)
motors.largeBC.setSpeed(-50) motors.largeBC.setSpeed(-50)
loops.pause(2000) loops.pause(2000)

View File

@ -19,17 +19,13 @@ loops.pause(1000)
music.playSoundEffectUntilDone(sounds.communicationGo) music.playSoundEffectUntilDone(sounds.communicationGo)
for (let d of drive) { for (let d of drive) {
if (d == 1) { if (d == 1) {
motors.largeC.setSpeedFor(50, 360, MoveUnit.Degrees) motors.largeC.setSpeed(50, 360, MoveUnit.Degrees)
motors.largeC.pauseUntilReady()
} else if (d == 3) { } else if (d == 3) {
motors.largeB.setSpeedFor(50, 360, MoveUnit.Degrees) motors.largeB.setSpeed(50, 360, MoveUnit.Degrees)
motors.largeB.pauseUntilReady()
} else if (d == 4) { } else if (d == 4) {
motors.largeBC.setSpeedFor(50, 360, MoveUnit.Degrees) motors.largeBC.setSpeed(50, 360, MoveUnit.Degrees)
motors.largeBC.pauseUntilReady()
} else { } else {
motors.largeBC.setSpeedFor(-50, 360, MoveUnit.Degrees) motors.largeBC.setSpeed(-50, 360, MoveUnit.Degrees)
motors.largeBC.pauseUntilReady()
} }
} }
music.playSoundEffectUntilDone(sounds.communicationGameOver) music.playSoundEffectUntilDone(sounds.communicationGameOver)

View File

@ -23,17 +23,13 @@ loops.pause(1000)
music.playSoundEffectUntilDone(sounds.communicationGo) music.playSoundEffectUntilDone(sounds.communicationGo)
for (let d of drive) { for (let d of drive) {
if (d == 1) { if (d == 1) {
motors.largeC.setSpeedFor(50, 360, MoveUnit.Degrees) motors.largeC.setSpeed(50, 360, MoveUnit.Degrees)
motors.largeC.pauseUntilReady()
} else if (d == 3) { } else if (d == 3) {
motors.largeB.setSpeedFor(50, 360, MoveUnit.Degrees) motors.largeB.setSpeed(50, 360, MoveUnit.Degrees)
motors.largeB.pauseUntilReady()
} else if (d == 4) { } else if (d == 4) {
motors.largeBC.setSpeedFor(50, 360, MoveUnit.Degrees) motors.largeBC.setSpeed(50, 360, MoveUnit.Degrees)
motors.largeBC.pauseUntilReady()
} else { } else {
motors.largeBC.setSpeedFor(-50, 360, MoveUnit.Degrees) motors.largeBC.setSpeed(-50, 360, MoveUnit.Degrees)
motors.largeBC.pauseUntilReady()
} }
} }
music.playSoundEffectUntilDone(sounds.communicationGameOver) music.playSoundEffectUntilDone(sounds.communicationGameOver)

View File

@ -3,10 +3,10 @@
Use a touch sensor to make the brick happy. Use a touch sensor to make the brick happy.
```blocks ```blocks
sensors.touchSensor1.onEvent(TouchSensorEvent.Pressed, function () { sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
brick.showImage(images.expressionsBigSmile) brick.showImage(images.expressionsBigSmile)
}) })
sensors.touchSensor1.onEvent(TouchSensorEvent.Released, function () { sensors.touch1.onEvent(TouchSensorEvent.Released, function () {
brick.showImage(images.expressionsSick) brick.showImage(images.expressionsSick)
}) })
``` ```

View File

@ -2,10 +2,8 @@
This program will activate an alarm when an object moves in front of the Ultrasonic Sensor. This program will activate an alarm when an object moves in front of the Ultrasonic Sensor.
TODO support for event when value changes
```blocks ```blocks
input.ultrasonic4.onObjectNear(function () { sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
music.playSoundUntilDone(music.sounds(Sounds.PowerUp)) music.playSoundEffectUntilDone(sounds.informationActivate)
}) })
``` ```

View File

@ -4,14 +4,12 @@ Use this program with the Programmable Brick and Large Motor.
```blocks ```blocks
loops.forever(function () { loops.forever(function () {
output.largeMotorA.setPower(30) motors.largeA.setSpeed(30)
output.largeMotorA.on(true)
loops.pause(100) loops.pause(100)
output.largeMotorA.on(false) motors.largeA.stop()
music.playSoundUntilDone(music.sounds(Sounds.PowerUp)) music.playSoundEffectUntilDone(sounds.animalsCatPurr)
output.largeMotorA.setPower(-30) motors.largeA.setSpeed(-30)
output.largeMotorA.on(true)
loops.pause(100) loops.pause(100)
output.largeMotorA.on(false) motors.largeA.stop()
}) })
``` ```

View File

@ -3,7 +3,7 @@
This program will activate an alarm when an object is lifted from the Touch Sensor. This program will activate an alarm when an object is lifted from the Touch Sensor.
```blocks ```blocks
input.touchSensor1.onEvent(TouchSensorEvent.Released, function () { sensors.touch1.onEvent(TouchSensorEvent.Released, function () {
music.playSoundUntilDone(music.sounds(Sounds.PowerUp)) music.playSoundEffectUntilDone(sounds.informationActivate);
}) })
``` ```

View File

@ -4,9 +4,9 @@ This example program combined with the small model will make a beat and rhythm o
```blocks ```blocks
loops.forever(function () { loops.forever(function () {
output.motorA.on(50) motors.largeA.setSpeed(50)
loops.pause(200) loops.pause(200)
output.motorA.on(100) motors.largeA.setSpeed(100)
loops.pause(200) loops.pause(200)
}) })
``` ```

View File

@ -3,13 +3,13 @@
This program will play different sounds when the wheel is rotated. The sound is determined by which color is placed in front of the color Sensor. This program will play different sounds when the wheel is rotated. The sound is determined by which color is placed in front of the color Sensor.
```blocks ```blocks
input.color3.onColorDetected(ColorSensorColor.Blue, function () { sensors.color3.onColorDetected(ColorSensorColor.Blue, function () {
music.playTone(Note.G4, music.beat(BeatFraction.Half)) music.playTone(Note.G4, music.beat(BeatFraction.Half))
}) })
input.color3.onColorDetected(ColorSensorColor.Red, function () { sensors.color3.onColorDetected(ColorSensorColor.Red, function () {
music.playTone(Note.C5, music.beat(BeatFraction.Half)) music.playTone(Note.C5, music.beat(BeatFraction.Half))
}) })
input.color3.onColorDetected(ColorSensorColor.Green, function () { sensors.color3.onColorDetected(ColorSensorColor.Green, function () {
music.playTone(Note.D5, music.beat(BeatFraction.Half)) music.playTone(Note.D5, music.beat(BeatFraction.Half))
}) })
``` ```

View File

@ -3,9 +3,9 @@
```blocks ```blocks
loops.forever(function () { loops.forever(function () {
if (sensors.color1.ambientLight() > 20) { if (sensors.color1.ambientLight() > 20) {
brick.setStatusLight(LightsPattern.Green) brick.setLight(BrickLight.Green)
} else { } else {
brick.setStatusLight(LightsPattern.Orange) brick.setLight(BrickLight.Orange)
} }
}) })
``` ```

View File

@ -3,9 +3,9 @@
```blocks ```blocks
loops.forever(function () { loops.forever(function () {
if (sensors.color1.color() == ColorSensorColor.Green) { if (sensors.color1.color() == ColorSensorColor.Green) {
brick.setStatusLight(LightsPattern.Green) brick.setLight(BrickLight.Green)
} else { } else {
brick.setStatusLight(LightsPattern.Orange) brick.setLight(BrickLight.Orange)
} }
}) })
``` ```

View File

@ -3,9 +3,9 @@
```blocks ```blocks
loops.forever(function () { loops.forever(function () {
if (sensors.color1.reflectedLight() > 20) { if (sensors.color1.reflectedLight() > 20) {
brick.setStatusLight(LightsPattern.Green) brick.setLight(BrickLight.Green)
} else { } else {
brick.setStatusLight(LightsPattern.Orange) brick.setLight(BrickLight.Orange)
} }
}) })
``` ```

View File

@ -1,11 +1,11 @@
# Touch Sensor # Touch Sensor
```cards ```cards
sensors.touchSensor1.onEvent(TouchSensorEvent.Pressed, function () { sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
brick.showImage(images.expressionsBigSmile) brick.showImage(images.expressionsBigSmile)
}) })
sensors.touchSensor1.isPressed(); sensors.touch1.isPressed();
sensors.touchSensor1.wasPressed(); sensors.touch1.wasPressed();
``` ```
## See Also ## See Also

View File

@ -2,10 +2,10 @@
```blocks ```blocks
loops.forever(function () { loops.forever(function () {
if (sensors.touchSensor1.isPressed()) { if (sensors.touch1.isPressed()) {
brick.setStatusLight(LightsPattern.Green) brick.setLight(BrickLight.Green)
} else { } else {
brick.setStatusLight(LightsPattern.Orange) brick.setLight(BrickLight.Orange)
} }
}) })
``` ```

View File

@ -1,7 +1,7 @@
# On Event # On Event
```sig ```sig
sensors.touchSensor1.onEvent(TouchSensorEvent.Released, function () { }) sensors.touch1.onEvent(TouchSensorEvent.Released, function () { })
``` ```
# Parameters # Parameters
@ -10,7 +10,7 @@ sensors.touchSensor1.onEvent(TouchSensorEvent.Released, function () { })
```blocks ```blocks
sensors.touchSensor1.onEvent(TouchSensorEvent.Released, function () { sensors.touch1.onEvent(TouchSensorEvent.Released, function () {
brick.showImage(images.expressionsSick) brick.showImage(images.expressionsSick)
}) })
``` ```

View File

@ -2,10 +2,10 @@
```blocks ```blocks
loops.forever(function () { loops.forever(function () {
if (sensors.touchSensor1.wasPressed()) { if (sensors.touch1.wasPressed()) {
brick.setStatusLight(LightsPattern.Green) brick.setLight(BrickLight.Green)
} else { } else {
brick.setStatusLight(LightsPattern.Orange) brick.setLight(BrickLight.Orange)
} }
}) })
``` ```