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
## 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)
* [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:
```block
input.buttonA.onEvent(ButtonEvent.Click, () => {
light.showRing(`blue blue blue blue blue blue blue blue blue blue`)
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
motors.largeA.setSpeed(50)
})
```
```typescript
input.buttonA.onEvent(ButtonEvent.Click, () => {
light.showRing(`blue blue blue blue blue blue blue blue blue blue`)
brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
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)
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
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
@ -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.
```sim
loops.forever(() => {
light.pixels.showAnimation(light.animation(LightAnimation.Rainbow), 1000)
brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
motors.largeA.setSpeed(50)
})
```
```package
light
```

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,10 +3,10 @@
Use a touch sensor to make the brick happy.
```blocks
sensors.touchSensor1.onEvent(TouchSensorEvent.Pressed, function () {
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
brick.showImage(images.expressionsBigSmile)
})
sensors.touchSensor1.onEvent(TouchSensorEvent.Released, function () {
sensors.touch1.onEvent(TouchSensorEvent.Released, function () {
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.
TODO support for event when value changes
```blocks
input.ultrasonic4.onObjectNear(function () {
music.playSoundUntilDone(music.sounds(Sounds.PowerUp))
sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
music.playSoundEffectUntilDone(sounds.informationActivate)
})
```

View File

@ -4,14 +4,12 @@ Use this program with the Programmable Brick and Large Motor.
```blocks
loops.forever(function () {
output.largeMotorA.setPower(30)
output.largeMotorA.on(true)
motors.largeA.setSpeed(30)
loops.pause(100)
output.largeMotorA.on(false)
music.playSoundUntilDone(music.sounds(Sounds.PowerUp))
output.largeMotorA.setPower(-30)
output.largeMotorA.on(true)
motors.largeA.stop()
music.playSoundEffectUntilDone(sounds.animalsCatPurr)
motors.largeA.setSpeed(-30)
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.
```blocks
input.touchSensor1.onEvent(TouchSensorEvent.Released, function () {
music.playSoundUntilDone(music.sounds(Sounds.PowerUp))
sensors.touch1.onEvent(TouchSensorEvent.Released, function () {
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
loops.forever(function () {
output.motorA.on(50)
motors.largeA.setSpeed(50)
loops.pause(200)
output.motorA.on(100)
motors.largeA.setSpeed(100)
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.
```blocks
input.color3.onColorDetected(ColorSensorColor.Blue, function () {
sensors.color3.onColorDetected(ColorSensorColor.Blue, function () {
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))
})
input.color3.onColorDetected(ColorSensorColor.Green, function () {
sensors.color3.onColorDetected(ColorSensorColor.Green, function () {
music.playTone(Note.D5, music.beat(BeatFraction.Half))
})
```

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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