hiding the was pressed block (#401)

This commit is contained in:
Peli de Halleux 2018-04-03 04:10:35 -07:00 committed by GitHub
parent 6c626f9c98
commit c0413aa192
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 14 additions and 12 deletions

View File

@ -22,7 +22,7 @@ Play some motor sounds if touch sensor `1` is pressed at the same moment when an
```blocks ```blocks
while (true) { while (true) {
if (sensors.touch1.wasPressed() && if (sensors.touch1.isPressed() &&
sensors.ultrasonic4.distance() < 10) { sensors.ultrasonic4.distance() < 10) {
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart) music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle); music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
@ -38,8 +38,8 @@ Play some motor sounds if touch sensor `1` is pressed when both the `enter` butt
```blocks ```blocks
while (true) { while (true) {
if (sensors.ultrasonic4.distance() < 10 && if (sensors.ultrasonic4.distance() < 10 &&
sensors.touch1.wasPressed() && sensors.touch1.isPressed() &&
brick.buttonEnter.wasPressed()) { brick.buttonEnter.isPressed()) {
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart) music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle); music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
} }

View File

@ -14,7 +14,7 @@ v = sensors.color3.light(LightIntensityMode.Reflected)
min = v min = v
max = v max = v
setpoint = v setpoint = v
while (!(brick.buttonEnter.wasPressed())) { while (!(brick.buttonEnter.isPressed())) {
brick.clearScreen() brick.clearScreen()
brick.showString("Move robot on terrain", 1) brick.showString("Move robot on terrain", 1)
brick.showString("Press ENTER when done", 2) brick.showString("Press ENTER when done", 2)

View File

@ -20,8 +20,8 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
}); });
brick.buttonEnter.pauseUntil(ButtonEvent.Bumped); brick.buttonEnter.pauseUntil(ButtonEvent.Bumped);
brick.buttonEnter.isPressed() brick.buttonEnter.isPressed()
brick.buttonEnter.wasPressed()
brick.setStatusLight(StatusLight.Red); brick.setStatusLight(StatusLight.Red);
brick.buttonEnter.wasPressed()
``` ```
## Other ## Other

View File

@ -14,7 +14,7 @@ The fact that a button was pressed earlier is remembered. Once **was pressed** i
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`. 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 ```typescript
if (sensors.touch1.wasPressed()) { if (sensors.touch1.wasPressed()) {
console.log("Hey, I was pressed."); console.log("Hey, I was pressed.");
} }
@ -32,7 +32,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. 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 ```typescript
brick.buttonLeft.onEvent(ButtonEvent.Bumped, function() { brick.buttonLeft.onEvent(ButtonEvent.Bumped, function() {
if (brick.buttonRight.wasPressed()) { if (brick.buttonRight.wasPressed()) {
brick.setStatusLight(StatusLight.Green) brick.setStatusLight(StatusLight.Green)
@ -45,6 +45,5 @@ brick.buttonLeft.onEvent(ButtonEvent.Bumped, function() {
## See also ## See also
[is pressed](/reference/brick/button/is-pressed), [is pressed](/reference/brick/button/is-pressed),
[on event](/reference/brick/button/on-event) [on event](/reference/brick/button/on-event),
[Touch sensors](/reference/sensors/touch-sensor) [Touch sensors](/reference/sensors/touch-sensor)

View File

@ -17,8 +17,8 @@ sensors.color(ColorSensorColor.Blue)
```cards ```cards
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {}) sensors.touch1.onEvent(ButtonEvent.Pressed, function () {})
sensors.touch1.pauseUntil(ButtonEvent.Pressed) sensors.touch1.pauseUntil(ButtonEvent.Pressed)
sensors.touch1.wasPressed()
sensors.touch1.isPressed() sensors.touch1.isPressed()
sensors.touch1.wasPressed()
``` ```
## Gyro ## Gyro

View File

@ -95,6 +95,7 @@ namespace brick {
//% help=brick/button/was-pressed //% help=brick/button/was-pressed
//% block="%button|was pressed" //% block="%button|was pressed"
//% blockId=buttonWasPressed //% blockId=buttonWasPressed
//% blockHidden=true
//% parts="brick" //% parts="brick"
//% blockNamespace=brick //% blockNamespace=brick
//% weight=80 //% weight=80

View File

@ -26,7 +26,7 @@ In order to recognize a button event signalled from a remote beacon, an infrared
If the beacon button ``top left`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`. If the beacon button ``top left`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`.
```blocks ```typescript
sensors.infrared1.setRemoteChannel(InfraredRemoteChannel.Ch0) sensors.infrared1.setRemoteChannel(InfraredRemoteChannel.Ch0)
forever(function () { forever(function () {
if (sensors.remoteButtonTopLeft.wasPressed()) { if (sensors.remoteButtonTopLeft.wasPressed()) {

View File

@ -101,6 +101,7 @@ namespace sensors {
//% help=sensors/beacon/was-pressed //% help=sensors/beacon/was-pressed
//% block="**remote button** %button|was pressed" //% block="**remote button** %button|was pressed"
//% blockId=remotebuttonWasPressed //% blockId=remotebuttonWasPressed
//% blockHidden=true
//% parts="remote" //% parts="remote"
//% blockNamespace=sensors //% blockNamespace=sensors
//% weight=80 //% weight=80

View File

@ -16,7 +16,7 @@ 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`. If the touch sensor ``touch 1`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`.
```blocks ```typescript
forever(function () { forever(function () {
if (sensors.touch1.wasPressed()) { if (sensors.touch1.wasPressed()) {
brick.setStatusLight(StatusLight.Green) brick.setStatusLight(StatusLight.Green)

View File

@ -83,6 +83,7 @@ namespace sensors {
//% help=sensors/touch-sensor/was-pressed //% help=sensors/touch-sensor/was-pressed
//% block="**touch** %this|was pressed" //% block="**touch** %this|was pressed"
//% blockId=touchWasPressed //% blockId=touchWasPressed
//% blockHidden=true
//% parts="touch" //% parts="touch"
//% blockNamespace=sensors //% blockNamespace=sensors
//% this.fieldEditor="ports" //% this.fieldEditor="ports"