This commit is contained in:
Juri
2020-08-19 22:03:58 +02:00
parent 4ef7b9318f
commit 3152215415
291 changed files with 9511 additions and 2966 deletions

View File

@ -23,7 +23,7 @@ confuse the @boardname@.
This example runs the calibration when the user presses **A+B** buttons.
```blocks
input.onButtonEvent(Button.AB, ButtonEvent.Click, () => {
input.onButtonPressed(Button.AB, () => {
input.calibrateCompass();
})
```

View File

@ -70,7 +70,7 @@ confuse the @boardname@.
Keep the calibration handy by running it when the user pressed **A+B**.
```block
input.onButtonEvent(Button.AB, ButtonEvent.Click, () => {
input.onButtonPressed(Button.AB, () => {
input.calibrateCompass();
})
```

View File

@ -17,7 +17,7 @@ This program shows a number from `2` to `9` when you shake the @boardname@.
```blocks
forever(function() {
if (input.isGesture(Gesture.Shake)) {
let x = Math.randomRange(2, 9)
let x = randint(2, 9)
basic.showNumber(x)
}
})

View File

@ -29,7 +29,7 @@ program shows the light level
on the [LED screen](/device/screen).
```blocks
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
input.onButtonPressed(Button.B, () => {
let level = input.lightLevel()
basic.showNumber(level)
})

View File

@ -1,6 +1,6 @@
# On Button Pressed
Start an [event handler](/reference/event-handler) (part of the program that will run when something happens, like when a button is pressed).
Start an [event handler](/reference/event-handler) (part of the program that will run when something happens, like when a button is pressed).
This handler works when button `A` or `B` is pressed, or `A` and `B` together.
When you are using this function in a web browser, click the buttons on the screen instead of the ones
on the @boardname@.
@ -9,7 +9,7 @@ on the @boardname@.
* For `A` and `B` together: This handler works when `A` and `B` are both pushed down, then one of them is released within 1.5 seconds of pushing down the second button.
```sig
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {})
input.onButtonPressed(Button.A, () => {})
```
Find out how buttons provide input to the @boardname@ in this video:
@ -18,13 +18,13 @@ https://www.youtube.com/watch?v=t_Qujjd_38o
## Example: count button clicks
This example counts how many times you press the `A` button.
This example counts how many times you press the `A` button.
Each time you press the button, the [LED screen](/device/screen) shows the `count` variable getting bigger.
```blocks
let count = 0
basic.showNumber(count)
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
input.onButtonPressed(Button.A, () => {
count++;
basic.showNumber(count);
})
@ -35,8 +35,8 @@ input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
This example shows a number from 1 to 6 when you press the `B` button.
```blocks
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
let dice = Math.randomRange(0, 5) + 1
input.onButtonPressed(Button.B, () => {
let dice = randint(0, 5) + 1
basic.showNumber(dice)
})
```

View File

@ -19,7 +19,7 @@ This program shows a number from `2` to `9` when you shake the @boardname@.
```blocks
input.onGesture(Gesture.Shake,() => {
let x = Math.randomRange(2, 9)
let x = randint(2, 9)
basic.showNumber(x)
})
```

View File

@ -14,7 +14,7 @@ through your body and back into the @boardname@. This is called
**completing a circuit**. It's like you're a big wire!
```sig
input.onPinTouched(TouchPin.P0, Button.Click, () => {
input.onPinPressed(TouchPin.P0, () => {
})
```
@ -43,7 +43,7 @@ Every time you press the pin, the program shows the number of times on the scree
```blocks
let count = 0
basic.showNumber(count)
input.onPinTouched(TouchPin.P0, Button.Click, () => {
input.onPinPressed(TouchPin.P0, () => {
count = count + 1
basic.showNumber(count)
})

View File

@ -13,7 +13,7 @@ through your body and back into the @boardname@. This is called
**completing a circuit**. It's like you're a big wire!
```sig
input.onPinTouched(TouchPin.P0, ButtonEvent.Click, () => {
input.onPinReleased(TouchPin.P0, () => {
})
```
@ -36,7 +36,7 @@ Every time you release the pin, the program shows the number of times on the scr
```blocks
let count = 0
basic.showNumber(count, 100)
input.onPinTouched(TouchPin.P0, ButtonEvent.Click, () => {
input.onPinReleased(TouchPin.P0, () => {
count = count + 1
basic.showNumber(count, 100)
})

View File

@ -18,7 +18,7 @@ program finds the number of milliseconds since the program started
and shows it on the [LED screen](/device/screen).
```blocks
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
input.onButtonPressed(Button.B, () => {
let now = input.runningTime()
basic.showNumber(now)
})