Buttons rename (#287)
* renaming up/down/click to released/pressed/bump * missing images * fixing signature issue * updated strings * white lego logo
@ -7,12 +7,12 @@ Welcome to the **Microsoft MakeCode** editor for the **@boardname@**!
|
||||
You can program the @boardname@ using [Blocks](/blocks) or [JavaScript](/javascript) in your web browser:
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
motors.largeA.setSpeed(50)
|
||||
})
|
||||
```
|
||||
```typescript
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
motors.largeA.setSpeed(50)
|
||||
})
|
||||
```
|
||||
@ -33,7 +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
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
motors.largeA.setSpeed(50)
|
||||
})
|
||||
```
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
```blocks
|
||||
let speed = 0;
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed < 100)
|
||||
speed = speed + 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
```blocks
|
||||
let speed = 0;
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed < 100)
|
||||
speed = speed + 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
})
|
||||
sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch2.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed > -100)
|
||||
speed = speed - 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
|
@ -17,11 +17,11 @@ function update() {
|
||||
brick.showString("speed: " + speed, 1)
|
||||
motors.largeBC.setSpeed(speed)
|
||||
}
|
||||
sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch2.onEvent(ButtonEvent.Pressed, function () {
|
||||
accelerate()
|
||||
update()
|
||||
})
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
decelerate()
|
||||
update()
|
||||
})
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Ignition Activity 1
|
||||
|
||||
```blocks
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.eyesDizzy)
|
||||
})
|
||||
sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectDetected, function () {
|
||||
|
@ -7,7 +7,7 @@ sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Bright,
|
||||
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
|
||||
brick.showImage(images.objectsLightOn)
|
||||
})
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.objectsLightOn);
|
||||
})
|
||||
```
|
@ -1,9 +1,9 @@
|
||||
# Reversing the robot Activity 1
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.setSpeed(50)
|
||||
sensors.touch1.pauseUntil(TouchSensorEvent.Pressed)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(0)
|
||||
loops.pause(1000)
|
||||
brick.setLight(BrickLight.OrangeFlash)
|
||||
|
@ -1,10 +1,10 @@
|
||||
# Reversing the robot Activity 2
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
sensors.touch1.pauseUntil(TouchSensorEvent.Pressed)
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(50)
|
||||
sensors.touch2.pauseUntil(TouchSensorEvent.Pressed)
|
||||
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(0)
|
||||
loops.pause(1000)
|
||||
brick.setLight(BrickLight.OrangeFlash)
|
||||
|
@ -1,12 +1,12 @@
|
||||
# Reversing the robot Activity 3
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
brick.showImage(images.eyesSleeping)
|
||||
sensors.touch1.pauseUntil(TouchSensorEvent.Pressed)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
brick.showImage(images.eyesNeutral)
|
||||
motors.largeBC.setSpeed(50)
|
||||
sensors.touch2.pauseUntil(TouchSensorEvent.Pressed)
|
||||
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
||||
brick.showImage(images.eyesTiredMiddle)
|
||||
motors.largeBC.setSpeed(0)
|
||||
loops.pause(1000)
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
```blocks
|
||||
let drive: number[] = []
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Bumped, function () {
|
||||
drive.push(1)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonRight.onEvent(ButtonEvent.Bumped, function () {
|
||||
drive.push(3)
|
||||
})
|
||||
brick.buttonUp.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonUp.onEvent(ButtonEvent.Bumped, function () {
|
||||
drive.push(4)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonDown.onEvent(ButtonEvent.Bumped, function () {
|
||||
drive.push(5)
|
||||
})
|
||||
pauseUntil(() => drive.length >= 5)
|
||||
|
@ -2,23 +2,23 @@
|
||||
|
||||
```blocks
|
||||
let drive: number[] = []
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Bumped, function () {
|
||||
drive.push(1)
|
||||
music.playSoundEffectUntilDone(sounds.systemClick)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonRight.onEvent(ButtonEvent.Bumped, function () {
|
||||
drive.push(3)
|
||||
music.playSoundEffectUntilDone(sounds.systemClick)
|
||||
})
|
||||
brick.buttonUp.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonUp.onEvent(ButtonEvent.Bumped, function () {
|
||||
drive.push(4)
|
||||
music.playSoundEffectUntilDone(sounds.systemClick)
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonDown.onEvent(ButtonEvent.Bumped, function () {
|
||||
drive.push(5)
|
||||
music.playSoundEffectUntilDone(sounds.systemClick)
|
||||
})
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Click);
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped);
|
||||
loops.pause(1000)
|
||||
music.playSoundEffectUntilDone(sounds.communicationGo)
|
||||
for (let d of drive) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Three Point Turn Activity 1
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.tank(75, 30)
|
||||
loops.pause(1500)
|
||||
motors.largeBC.tank(-30, -75)
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Three Point Turn Activity 2
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.tank(75, 30)
|
||||
loops.pause(1500)
|
||||
motors.largeBC.tank(-30, -75)
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Three Point Turn Activity 3
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.tank(75, 30)
|
||||
loops.pause(1500)
|
||||
motors.largeBC.tank(-30, -75)
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Traffic Lights Activity 1
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.tank(20, 20)
|
||||
sensors.color3.pauseForColor(ColorSensorColor.Red)
|
||||
motors.largeBC.tank(0, 0)
|
||||
|
@ -111,7 +111,7 @@ function stop() {
|
||||
motors.stopAllMotors()
|
||||
state = 0
|
||||
moods.knockedOut.show();
|
||||
sensors.touch3.pauseUntil(TouchSensorEvent.Pressed)
|
||||
sensors.touch3.pauseUntil(ButtonEvent.Pressed)
|
||||
moods.neutral.show();
|
||||
}
|
||||
sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
|
||||
|
@ -149,7 +149,7 @@ loops.forever(function () {
|
||||
brick.setLight(BrickLight.RedPulse);
|
||||
brick.showImage(images.eyesKnockedOut)
|
||||
music.playSoundEffect(sounds.movementsSpeedDown)
|
||||
sensors.touch3.pauseUntil(TouchSensorEvent.Pressed)
|
||||
sensors.touch3.pauseUntil(ButtonEvent.Pressed)
|
||||
brick.setLight(BrickLight.Off);
|
||||
})
|
||||
|
||||
|
@ -11,7 +11,7 @@ function INI() {
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.setSpeed(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.setSpeed(50)
|
||||
sensors.touch1.pauseUntil(TouchSensorEvent.Pressed);
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed);
|
||||
motors.largeC.setSpeed(-50, 0.86, MoveUnit.Rotations);
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ function INI() {
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.setSpeed(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.setSpeed(50)
|
||||
sensors.touch1.pauseUntil(TouchSensorEvent.Pressed);
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed);
|
||||
motors.largeC.setSpeed(-50, 0.86, MoveUnit.Rotations);
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ loops.forever(function () {
|
||||
brick.setLight(BrickLight.RedPulse);
|
||||
brick.showImage(images.eyesKnockedOut)
|
||||
music.playSoundEffect(sounds.movementsSpeedDown)
|
||||
sensors.touch3.pauseUntil(TouchSensorEvent.Pressed)
|
||||
sensors.touch3.pauseUntil(ButtonEvent.Pressed)
|
||||
brick.setLight(BrickLight.Off);
|
||||
})
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
Use a touch sensor to make the brick happy.
|
||||
|
||||
```blocks
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsBigSmile)
|
||||
})
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Released, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Released, function () {
|
||||
brick.showImage(images.expressionsSick)
|
||||
})
|
||||
```
|
@ -44,7 +44,7 @@ loops.forever(function () {
|
||||
lasterror = error
|
||||
if (brick.buttonEnter.wasPressed()) {
|
||||
motors.largeBC.setSpeed(0)
|
||||
brick.buttonDown.pauseUntil(ButtonEvent.Click)
|
||||
brick.buttonDown.pauseUntil(ButtonEvent.Bumped)
|
||||
}
|
||||
})
|
||||
```
|
@ -3,7 +3,7 @@
|
||||
This program will activate an alarm when an object is lifted from the Touch Sensor.
|
||||
|
||||
```blocks
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Released, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Released, function () {
|
||||
music.playSoundEffectUntilDone(sounds.informationActivate);
|
||||
})
|
||||
```
|
@ -15,10 +15,10 @@ brick.printPorts();
|
||||
## Buttons
|
||||
|
||||
```cards
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
|
||||
});
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Click);
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped);
|
||||
brick.buttonEnter.isPressed()
|
||||
brick.buttonEnter.wasPressed()
|
||||
brick.setLight(BrickLight.Red);
|
||||
|
@ -3,7 +3,7 @@
|
||||
Run some code when a button is clicked, pressed down, or released.
|
||||
|
||||
```sig
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
|
||||
});
|
||||
```
|
||||
@ -15,7 +15,7 @@ brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
Your @boardname@ has touch sensors that work like buttons. Instead of saying `enter` or `left` as the source button, use a touch sensor block with a sensor name like `touch 1`.
|
||||
|
||||
```block
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.setLight(BrickLight.Orange);
|
||||
});
|
||||
```
|
||||
@ -38,13 +38,13 @@ Check for event on the ENTER button. Put a message on the screen when the button
|
||||
|
||||
```blocks
|
||||
brick.showString("ENTER is: UP", 1);
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Up, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Released, function () {
|
||||
brick.showString("ENTER is: UP ", 1);
|
||||
});
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Down, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showString("ENTER is: DOWN ", 1);
|
||||
});
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
brick.showString("ENTER was: CLICKED", 1);
|
||||
});
|
||||
```
|
||||
|
@ -3,7 +3,7 @@
|
||||
Causes your program to wait until an event at a button happens.
|
||||
|
||||
```sig
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Click);
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped);
|
||||
```
|
||||
|
||||
## Parameters
|
||||
@ -23,7 +23,7 @@ brick.showString("We're going to wait", 1);
|
||||
brick.showString("for you to press and", 2);
|
||||
brick.showString("release the UP button", 3);
|
||||
waitTime = control.millis();
|
||||
brick.buttonUp.pauseUntil(ButtonEvent.Click);
|
||||
brick.buttonUp.pauseUntil(ButtonEvent.Bumped);
|
||||
brick.clearScreen();
|
||||
if (control.millis() - waitTime > 5000) {
|
||||
brick.showString("Ok, that took awhile!", 1)
|
||||
|
@ -33,7 +33,7 @@ Read about [touch sensors](/reference/sensors/touch-sensor) and using them as to
|
||||
Set the brick light to green if the `right` button was pressed before the `left` button. If not, the brick light is turned off when the `left` button is pressed.
|
||||
|
||||
```blocks
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Click, function() {
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Bumped, function() {
|
||||
if (brick.buttonRight.wasPressed()) {
|
||||
brick.setLight(BrickLight.Green)
|
||||
} else {
|
||||
|
@ -18,7 +18,7 @@ Show a greeting on the screen. Then, respond with another message when ENTER is
|
||||
```blocks
|
||||
brick.showString("Hello, I dare you to", 1);
|
||||
brick.showString("press ENTER...", 2);
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
brick.showString("Hey! Don't push my", 4);
|
||||
brick.showString("buttons.", 5);
|
||||
});
|
||||
|
@ -3,7 +3,7 @@
|
||||
Show a name-value-pair on the screen at the line you select.
|
||||
|
||||
```sig
|
||||
brick.showNumber("item", 0, 1);
|
||||
brick.showValue("item", 0, 1);
|
||||
```
|
||||
|
||||
Name-value-pairs are used to report data values to the screen. If you want to show the current temperature on the screen, you might use `"temp"` as the data name for the the value.
|
||||
@ -19,7 +19,7 @@ Name-value-pairs are used to report data values to the screen. If you want to sh
|
||||
Show the current amount of ambient light detected by sensor 2.
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
brick.showValue("color", sensors.color2.light(LightIntensityMode.Ambient), 1)
|
||||
})
|
||||
```
|
||||
|
BIN
docs/static/configurations/chrome-version.png
vendored
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
docs/static/configurations/edge-version.png
vendored
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
docs/static/configurations/firefox-version.png
vendored
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
docs/static/configurations/ie-version.png
vendored
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
docs/static/configurations/osx-version.png
vendored
Normal file
After Width: | Height: | Size: 128 KiB |
BIN
docs/static/configurations/safari-version.png
vendored
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
docs/static/configurations/windows-version.png
vendored
Normal file
After Width: | Height: | Size: 82 KiB |
64
docs/static/lego-logo-white.svg
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" id="svg10" width="236.9" height="56.7">
|
||||
<defs id="defs14">
|
||||
<clipPath id="clipPath26">
|
||||
<path d="M332 275.6h177.7v42.5H332z" id="path24"/>
|
||||
</clipPath>
|
||||
<clipPath id="clipPath76">
|
||||
<path d="M332 275.6h177.7v42.5H332z" id="path74"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
<g id="g18" transform="matrix(1.33333 0 0 -1.33333 0 56.7)">
|
||||
<g id="g130" transform="translate(-332 -275.6)">
|
||||
<g id="g20">
|
||||
<g clip-path="url(#clipPath26)" id="g22">
|
||||
<g transform="translate(387.6 297.7)" id="g28">
|
||||
<path id="path30" d="M0 0h6.3c0 1.4-.2 2.2-.5 2.6-.4.3-1.3.5-2.7.5C1.7 3 .8 2.9.5 2.5.2 2 0 1.3 0 0m6.3-4.1h3.4c0-2-.6-3.3-1.8-4-.8-.4-2.4-.6-4.8-.6-2.6 0-4.4.5-5.3 1.6-.8 1-1.2 2.8-1.2 5.5S-3 3-2.2 4C-1.4 5.1.4 5.7 3 5.7 6 5.7 7.8 5 8.6 4c.7-1 1.1-3 1.1-6.2H0c0-1.7.1-2.7.4-3.2.4-.6 1.3-.8 2.7-.8 1.2 0 2 0 2.3.2.6.3 1 .9 1 1.8" fill="#fff"/>
|
||||
</g>
|
||||
<g transform="translate(406.4 300.7)" id="g32">
|
||||
<path id="path34" d="M0 0c-1.4 0-2.2-.4-2.6-1.1a7 7 0 0 1-.5-3c0-2 .2-3.3.4-3.8.4-.9 1.3-1.3 2.7-1.3 1.6 0 2.6.4 3 1.2.3.6.4 1.8.4 3.8a7 7 0 0 1-.5 3.1C2.4-.4 1.5 0 0 0m3.4-11.7v2.2C2.7-11 1.2-11.8-1-11.8c-2.4 0-4 .7-4.7 2.2-.5 1-.7 2.7-.7 5.4 0 2.3.3 4 .9 5C-4.8 2-3.3 2.5-1 2.5s3.7-.7 4.2-2h.2v7.9h3.3v-20.2z" fill="#fff"/>
|
||||
</g>
|
||||
<g transform="translate(428.8 289)" id="g36">
|
||||
<path id="path38" d="M0 0h-3.3v2.2C-4 .6-5.6-.1-7.9-.1c-3.2 0-4.8 1.3-4.8 4v10.2h3.4V5.2c0-1 .1-1.8.4-2.1.3-.4 1-.7 2-.7 1.2 0 2.1.3 2.6.9.5.5.8 1.4.8 2.7v8H0z" fill="#fff"/>
|
||||
</g>
|
||||
<g transform="translate(441 294.4)" id="g40">
|
||||
<path id="path42" d="M0 0h3.4c0-2.3-.5-3.8-1.6-4.6-.8-.6-2.4-1-4.8-1-2.7 0-4.4.6-5.2 1.7-.8 1-1.1 2.8-1.1 5.6 0 2.7.3 4.5 1 5.4C-7.3 8.3-5.6 9-3 9c2.3 0 3.9-.3 4.8-1 1-.6 1.6-2 1.6-4.1H0c0 1-.2 1.8-.7 2-.4.4-1.2.5-2.3.5-1.4 0-2.3-.3-2.6-1-.2-.5-.4-1.7-.4-3.6 0-2 .1-3.2.4-3.6.3-.7 1.2-1 2.6-1 1.3 0 2 .1 2.4.5.4.3.6 1.1.6 2.4" fill="#fff"/>
|
||||
</g>
|
||||
<g transform="translate(452.8 295.4)" id="g44">
|
||||
<path id="path46" d="M0 0c-1.1 0-1.8 0-2.2-.2-.6-.3-1-1-1-1.8 0-1 .3-1.6.8-1.8.4-.3 1.2-.4 2.4-.4 1.1 0 1.8.1 2.2.3.6.3 1 1 1 1.9 0 .9-.4 1.4-1 1.7A6 6 0 0 1 0 0m3.1-6.3l.1 1.7c-.3-.8-1-1.3-1.9-1.6-.5-.2-1.4-.3-2.5-.3-1.8 0-3.1.3-4 .9C-6-5-6.4-3.8-6.4-2-6.5-.3-6 .8-5 1.5c.7.5 2 .8 3.8.8 1.1 0 2 0 2.5-.2C2 1.8 2.7 1.4 3 .7h.1v1.8c0 1.2-.1 2-.4 2.4-.4.5-1.3.7-2.6.7-.9 0-1.5 0-1.9-.3-.5-.3-.7-.8-.7-1.7H-6c0 1.9.6 3.1 1.8 3.7.8.4 2.2.6 4.2.6 2.4 0 4-.3 4.9-1 1-.7 1.5-2.2 1.5-4.4v-8.8z" fill="#fff"/>
|
||||
</g>
|
||||
<g transform="translate(460.9 300.6)" id="g48">
|
||||
<path id="path50" d="M0 0v2.6h1.8v3.2H5V2.6h5.5V0H5v-7.2c0-.7 0-1.2.2-1.4.2-.3.6-.5 1.3-.5.8 0 1.3.3 1.5 1l.2 2h3c0-2-.3-3.4-.8-4.2-.7-.9-2-1.4-3.9-1.4-1.8 0-3 .3-3.7.9-.8.6-1.1 1.8-1.1 3.6V0z" fill="#fff"/>
|
||||
</g>
|
||||
<path id="path52" d="M478.2 289h-3.4v14.2h3.4zm0 17.3h-3.4v3h3.4z" fill="#fff"/>
|
||||
<g transform="translate(487.5 300.7)" id="g54">
|
||||
<path id="path56" d="M0 0c-1.4 0-2.4-.3-2.8-1-.3-.4-.5-1.7-.5-3.6 0-2 .2-3.2.5-3.7.4-.6 1.3-1 2.8-1 1.5 0 2.4.4 2.8 1 .3.5.5 1.7.5 3.7S3-1.4 2.8-1C2.4-.3 1.5 0 0 0m0 2.6C2.8 2.6 4.7 2 5.5 1c.8-.9 1.1-2.7 1.1-5.6 0-2.9-.3-4.8-1-5.6-1-1-2.8-1.6-5.6-1.6s-4.7.5-5.5 1.6c-.8.8-1.1 2.7-1.1 5.6 0 2.9.3 4.7 1 5.6 1 1 2.8 1.6 5.6 1.6" fill="#fff"/>
|
||||
</g>
|
||||
<g transform="translate(497 303.2)" id="g58">
|
||||
<path id="path60" d="M0 0h3.4v-2.1A3 3 0 0 0 5.3-.2C6 0 6.7 0 8 0c1.8 0 3-.3 3.8-1 .7-.9 1-2.1 1-4v-9H9.4v9c0 1-.2 1.7-.6 2-.3.5-1 .7-2 .7-1.4 0-2.4-.4-2.8-1-.4-.6-.6-1.5-.6-3V-14H0z" fill="#fff"/>
|
||||
</g>
|
||||
<path id="path62" d="M384.5 316.4h125.2v1.7H384.5z" fill="#006cb6"/>
|
||||
<path id="path64" d="M384.5 275.6H471v1.7h-86.5z" fill="#006cb6"/>
|
||||
<path id="path66" d="M482.3 275.6h27.4v1.7h-27.4z" fill="#006cb6"/>
|
||||
</g>
|
||||
</g>
|
||||
<path id="path68" d="M332.3 275.9h42v42h-42z" fill="#fff"/>
|
||||
<g id="g70">
|
||||
<g clip-path="url(#clipPath76)" id="g72">
|
||||
<g transform="translate(371.5 300.4)" id="g78">
|
||||
<path id="path80" d="M0 0c0-1.3-.5-3-.9-4C-2.3-8.4-4-11.1-8-11.1c-1.2 0-3.2.3-4 2.4l-.2.5-.3-.5a6.5 6.5 0 0 0-5-2.4c-1.6 0-2.8.5-3.6 1.4l-.2.3-.2-.3c-.8-.9-2.3-1.4-4-1.4-1.4 0-2.5.4-3.3 1.3l-.2.2-.2-.2c-.8-.9-2.2-1.3-3.9-1.3-2 0-3.2 1.2-3.3 3 0 3 2.7 9 3.9 10.8a3.4 3.4 0 0 0 3.1 1.8c1 0 1.6-.2 2-.6.3-.4.4-.7.4-1.4v-1l.5.9c1.2 2 3.3 2.2 5.3 2.2 1.3 0 2.6-.5 3-1.3l.2-.3.3.2a6 6 0 0 0 4 1.4c1.8 0 3.1-.5 3.9-1.3l.4-.7.2-.4.3.3c1.1 1.4 2.6 2 4.5 2 1.5 0 2.6-.4 3.4-1.2C0 2.3 0 1 0 0m-39.2-24.5h42v42h-42z" fill="#ffed00"/>
|
||||
</g>
|
||||
<g transform="translate(372.7 298.8)" id="g82">
|
||||
<path id="path84" d="M0 0a24 24 0 0 0-1.8-5.5c-1.4-3-3.4-5.3-7.2-5.3-2 0-3.7.6-4.7 1.8a7.6 7.6 0 0 0-5-1.9 6 6 0 0 0-3.8 1.2 7.3 7.3 0 0 0-7.7 0 7 7 0 0 0-4-1.1C-37-10.8-39-9-39-6.5c0 3.3 2.7 9.4 4 11.5a5 5 0 0 0 4.4 2.4c2 0 2.7-.5 3-1.3 1.6 1.4 3.6 1.4 5 1.4 1.7 0 2.7-.4 3.5-1 1.2.6 2.6 1 4.2 1 2 0 3.6-.5 4.7-1.5a7 7 0 0 0 4.6 1.5c2.3 0 3.8-.9 4.7-2.1C.5 3.6.2 1.9 0 0m-40.3-22.9h42v42h-42z" fill="#e20614"/>
|
||||
</g>
|
||||
<path id="path86" d="M374 276.2h-41.4v41.3H374zm-42-.6h42.6v42.5H332z" fill="#1c1c1b"/>
|
||||
<g transform="translate(372.7 306.3)" id="g88">
|
||||
<path id="path90" d="M0 0a1 1 0 0 1-1-1c0-.6.4-1 1-1s1 .4 1 1C1-.5.6 0 0 0m0-.2a.8.8 0 1 0 0-1.6.8.8 0 0 0 0 1.6m.5-1.4l-.1.3-.2.2.3.3c0 .2-.2.3-.4.3h-.5v-1h.2v.4H0l.2-.3v-.2zm-.7.7v.2H0l.2-.1L0-.9z" fill="#1c1c1b"/>
|
||||
</g>
|
||||
<g transform="translate(367.4 300.5)" id="g92">
|
||||
<path id="path94" d="M0 0c0-1-1.6-5.4-2.2-6.4-.2-.4-.5-.7-1-.7s-.6.3-.7.6c0 1 1.8 6 2.4 6.7.3.4.6.5 1 .5C0 .7 0 .3 0 0m2.9-1.8c-.4-1.8-1.2-3.9-2-5.5-1.5-2.6-3.2-3-4.8-3-1.5 0-3.2.7-3.2 3 0 1.7.7 4 1.3 5.7 1 2.8 2.2 5.1 5.7 5 4 0 3.3-3.6 3-5.2m-13 2.5c-.5 0-.9-.3-1.2-.7-.6-1-2-4.5-2.2-6-.1-1 .3-1.1.8-1.1.7 0 1.6.8 1.9 2.1 0 0-1.5 0-1 1.3.3 1.3 1 1.5 2.2 1.6 2.4 0 2.2-1.7 2-2.6-.6-3-2.8-5.5-5.9-5.5-2 0-3.4 1.1-3.4 3.3 0 1.5.8 3.9 1.4 5.3 1.3 3 2.6 5 6 5 2 0 3.7-.7 3.5-2.6-.2-1.4-1-2.2-2.2-2.3-.4 0-1.8 0-1.3 1.4.1.5.2.8-.5.8m-10.7-5.2l-.6-2a7 7 0 0 0 2 .2c1.1 0 1.8-.4 1.8-1.3 0-2-2.3-2.6-3.9-2.6-1.7 0-3.2 1-3.2 2.8A21 21 0 0 0-22.3.4c1.4 2.8 2.8 3.1 5.2 3.1 1.1 0 2.3-.4 2.3-1.4 0-1.4-1.2-2-2.3-2H-19s-.4-.6-.8-1.7c2.2.3 3.1-.2 2.8-1.5-.5-1.7-2-1.8-3.8-1.4m-7-2c2.2.4 2.7-.4 2.6-1.1-.2-2.2-2.1-2.6-3.8-2.6-1.2 0-2.3.6-2.4 2 0 2.5 2.5 8.3 3.7 10.2.6 1 1.3 1.4 2.3 1.4 1 0 1.3-.5 1.3-1.1 0-1.7-2.8-6.8-3.6-8.8M-.3 4.7a6 6 0 0 1-4.7-2l-.5.7c-.9 1-2.2 1.4-4 1.4-1.8 0-3.3-.6-4.3-1.4-.5.8-1.8 1.4-3.3 1.4-2 0-4.2-.3-5.5-2.4 0 .8-.1 1.2-.5 1.6-.6.6-1.4.7-2.2.7-1.5 0-2.6-.6-3.4-2-1.1-1.8-4-7.9-3.9-10.8 0-2 1.3-3.3 3.6-3.4 1.8 0 3.2.5 4.1 1.4.8-.9 2-1.4 3.5-1.4 1.6 0 3.2.5 4.2 1.6.8-1 2.1-1.6 3.8-1.6 2.1 0 4 1 5.2 2.6.7-1.9 2.4-2.6 4.3-2.6 4.1 0 6 2.8 7.4 7.3.4 1 .8 2.7.9 4.1.1 2.4-.9 4.8-4.7 4.8" fill="#1c1c1b"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 6.9 KiB |
@ -9,9 +9,9 @@
|
||||
"BrickLight.RedFlash|block": "red flash",
|
||||
"BrickLight.RedPulse|block": "red pulse",
|
||||
"BrickLight.Red|block": "red",
|
||||
"ButtonEvent.Click|block": "click",
|
||||
"ButtonEvent.Down|block": "down",
|
||||
"ButtonEvent.Up|block": "up",
|
||||
"ButtonEvent.Bumped|block": "bumped",
|
||||
"ButtonEvent.Pressed|block": "pressed",
|
||||
"ButtonEvent.Released|block": "released",
|
||||
"MoveUnit.Degrees|block": "degrees",
|
||||
"MoveUnit.MilliSeconds|block": "milliseconds",
|
||||
"MoveUnit.Rotations|block": "rotations",
|
||||
|
@ -29,14 +29,15 @@ const enum BrickLight {
|
||||
* User interaction on buttons
|
||||
*/
|
||||
const enum ButtonEvent {
|
||||
//% block="click"
|
||||
Click = 1,
|
||||
//% block="up"
|
||||
Up = 3,
|
||||
//% block="down"
|
||||
Down = 4,
|
||||
//% block="pressed"
|
||||
Pressed = 4,
|
||||
//% block="bumped"
|
||||
Bumped = 1,
|
||||
//% block="released"
|
||||
Released = 3,
|
||||
}
|
||||
|
||||
|
||||
namespace brick {
|
||||
/**
|
||||
* Generic button class, for device buttons and sensors.
|
||||
@ -62,12 +63,12 @@ namespace brick {
|
||||
if (curr) {
|
||||
this._wasPressed = true;
|
||||
this.downTime = control.millis()
|
||||
control.raiseEvent(this._id, ButtonEvent.Down)
|
||||
control.raiseEvent(this._id, ButtonEvent.Pressed)
|
||||
} else {
|
||||
control.raiseEvent(this._id, ButtonEvent.Up)
|
||||
control.raiseEvent(this._id, ButtonEvent.Released)
|
||||
const delta = control.millis() - this.downTime;
|
||||
if (delta < 500)
|
||||
control.raiseEvent(this._id, ButtonEvent.Click)
|
||||
control.raiseEvent(this._id, ButtonEvent.Bumped)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,8 +66,8 @@ namespace console.screen {
|
||||
if (!lines) {
|
||||
lines = [];
|
||||
console.addListener(log);
|
||||
brick.buttonUp.onEvent(ButtonEvent.Click, () => scroll(-3))
|
||||
brick.buttonDown.onEvent(ButtonEvent.Click, () => scroll(3))
|
||||
brick.buttonUp.onEvent(ButtonEvent.Bumped, () => scroll(-3))
|
||||
brick.buttonDown.onEvent(ButtonEvent.Bumped, () => scroll(3))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,25 +6,25 @@ brick.setLight(BrickLight.Orange)
|
||||
|
||||
brick.heart.doubled().draw(100, 50, Draw.Double | Draw.Transparent)
|
||||
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
screen.clear()
|
||||
})
|
||||
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Bumped, () => {
|
||||
brick.drawRect(10, 70, 20, 10, Draw.Fill)
|
||||
brick.setLight(BrickLight.Red)
|
||||
brick.setFont(brick.microbitFont())
|
||||
})
|
||||
|
||||
brick.buttonRight.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonRight.onEvent(ButtonEvent.Bumped, () => {
|
||||
brick.print("Right!", 10, 60)
|
||||
})
|
||||
|
||||
brick.buttonDown.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonDown.onEvent(ButtonEvent.Bumped, () => {
|
||||
brick.print("Down! ", 10, 60)
|
||||
})
|
||||
|
||||
brick.buttonUp.onEvent(ButtonEvent.Click, () => {
|
||||
brick.buttonUp.onEvent(ButtonEvent.Bumped, () => {
|
||||
brick.print("Up! ", 10, 60)
|
||||
})
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
{
|
||||
"TouchSensorEvent": "Touch sensor interactions",
|
||||
"sensors.TouchSensor.isPressed": "Check if touch sensor is touched.",
|
||||
"sensors.TouchSensor.onEvent": "Do something when a touch sensor is touched...",
|
||||
"sensors.TouchSensor.onEvent|param|body": "code to run when the event is raised",
|
||||
|
@ -1,7 +1,4 @@
|
||||
{
|
||||
"TouchSensorEvent.Bumped|block": "bumped",
|
||||
"TouchSensorEvent.Pressed|block": "pressed",
|
||||
"TouchSensorEvent.Released|block": "released",
|
||||
"sensors.TouchSensor.isPressed|block": "%sensor|is pressed",
|
||||
"sensors.TouchSensor.onEvent|block": "on %sensor|%event",
|
||||
"sensors.TouchSensor.pauseUntil|block": "pause until %sensor|%event",
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Touch Sensor
|
||||
|
||||
```cards
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showImage(images.expressionsBigSmile)
|
||||
})
|
||||
sensors.touch1.isPressed();
|
||||
|
@ -1,7 +1,7 @@
|
||||
# On Event
|
||||
|
||||
```sig
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Released, function () { })
|
||||
sensors.touch1.onEvent(ButtonEvent.Released, function () { })
|
||||
```
|
||||
|
||||
# Parameters
|
||||
@ -10,7 +10,7 @@ sensors.touch1.onEvent(TouchSensorEvent.Released, function () { })
|
||||
|
||||
|
||||
```blocks
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Released, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Released, function () {
|
||||
brick.showImage(images.expressionsSick)
|
||||
})
|
||||
```
|
||||
|
@ -1,8 +1,8 @@
|
||||
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
})
|
||||
sensors.touch2.onEvent(TouchSensorEvent.Bumped, function () {
|
||||
sensors.touch2.onEvent(ButtonEvent.Bumped, function () {
|
||||
})
|
||||
sensors.touch3.onEvent(TouchSensorEvent.Released, function () {
|
||||
sensors.touch3.onEvent(ButtonEvent.Released, function () {
|
||||
})
|
||||
sensors.touch4.isPressed();
|
||||
sensors.touch4.wasPressed();
|
||||
|
@ -1,17 +1,5 @@
|
||||
// keep TouchSensorEvent in sync with ButtonEvent
|
||||
|
||||
/**
|
||||
* Touch sensor interactions
|
||||
*/
|
||||
const enum TouchSensorEvent {
|
||||
//% block="pressed"
|
||||
Pressed = 4,
|
||||
//% block="bumped"
|
||||
Bumped = 1,
|
||||
//% block="released"
|
||||
Released = 3,
|
||||
}
|
||||
|
||||
namespace sensors {
|
||||
|
||||
//% fixedInstances
|
||||
@ -48,8 +36,8 @@ namespace sensors {
|
||||
//% sensor.fieldEditor="ports"
|
||||
//% weight=99 blockGap=8
|
||||
//% group="Touch Sensor"
|
||||
onEvent(ev: TouchSensorEvent, body: () => void) {
|
||||
this.button.onEvent(<ButtonEvent><number>ev, body)
|
||||
onEvent(ev: ButtonEvent, body: () => void) {
|
||||
this.button.onEvent(ev, body)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +52,7 @@ namespace sensors {
|
||||
//% sensor.fieldEditor="ports"
|
||||
//% weight=98 blockGap=8
|
||||
//% group="Touch Sensor"
|
||||
pauseUntil(ev: TouchSensorEvent) {
|
||||
pauseUntil(ev: ButtonEvent) {
|
||||
this.button.pauseUntil(<ButtonEvent><number>ev);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
tests.test("Detect color red", function () {
|
||||
brick.print("Point sensor to red", 0, 50)
|
||||
brick.print("and click enter", 0, 60)
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Click)
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped)
|
||||
brick.clearScreen()
|
||||
let actualColor = sensors.color1.color()
|
||||
tests.assertClose("Color", actualColor, ColorSensorColor.Red, 0)
|
||||
@ -10,7 +10,7 @@ tests.test("Detect color red", function () {
|
||||
tests.test("Bright ambient light", function () {
|
||||
brick.print("Point sensor to ceiling", 0, 50)
|
||||
brick.print("light and click enter", 0, 60)
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Click)
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped)
|
||||
brick.clearScreen()
|
||||
let actualLight: number
|
||||
for (let i = 0; i < 4; i++) {
|
||||
@ -24,7 +24,7 @@ tests.test("Bright reflected light", function () {
|
||||
brick.print("Point sensor to white", 0, 50)
|
||||
brick.print("desk surface", 0, 60)
|
||||
brick.print("and click enter", 0, 70)
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Click)
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped)
|
||||
brick.clearScreen()
|
||||
let actualLight: number
|
||||
for (let i = 0; i < 4; i++) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
tests.test("Touch sensor pressed", function () {
|
||||
brick.print("Press touch sensor", 0, 50)
|
||||
brick.print("and click enter", 0, 60)
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Click)
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped)
|
||||
brick.clearScreen()
|
||||
tests.assert("Pressed", sensors.touch1.isPressed())
|
||||
})
|
@ -3,7 +3,7 @@ tests.test("Ultrasonic sensor", function () {
|
||||
brick.print("one finger's length", 0, 60)
|
||||
brick.print("in front of sensor", 0, 70)
|
||||
brick.print("and click enter", 0, 80)
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Click)
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped)
|
||||
brick.clearScreen()
|
||||
tests.assertClose("Distance", sensors.ultrasonic1.distance(), 7, 6)
|
||||
})
|