batch replace onButtonPressed(Button...
This commit is contained in:
@ -15,14 +15,14 @@ To create a new script, go to the [Create Code](/microbit/create-code) page and
|
||||
Begin by registering an event with `input->on pin pressed(PO)` to know when someone is holding pin ``P0`` and pin ``Gnd``.
|
||||
|
||||
```
|
||||
input.onPinPressed("P0", () => {
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
})
|
||||
```
|
||||
|
||||
We are going to create a meter that displays a random number from 0 to 10. We use ``11`` as `math->random(n)` returns a number between ``0`` and ``n-1``.
|
||||
|
||||
```
|
||||
input.onPinPressed("P0", () => {
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x = Math.random(11)
|
||||
})
|
||||
```
|
||||
@ -30,7 +30,7 @@ input.onPinPressed("P0", () => {
|
||||
Finally, let's show that number on the micro:bit.
|
||||
|
||||
```
|
||||
input.onPinPressed("P0", () => {
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x_ = Math.random(11)
|
||||
basic.showNumber(x_, 150)
|
||||
})
|
||||
|
@ -11,7 +11,7 @@ Complete the following guided tutorial:
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
input.onPinPressed("P0", () => {
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x = Math.random(11)
|
||||
basic.showNumber(x, 150)
|
||||
})
|
||||
@ -22,7 +22,7 @@ input.onPinPressed("P0", () => {
|
||||
Add a pause of 3000 milliseconds (3 seconds) after showing the number so that the number won't immediately disappear in the next challenge.
|
||||
|
||||
```
|
||||
input.onPinPressed("P0", () => {
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x1 = Math.random(11)
|
||||
basic.showNumber(x1, 150)
|
||||
basic.pause(3000) // ***
|
||||
@ -34,7 +34,7 @@ input.onPinPressed("P0", () => {
|
||||
If the rating **x** is between ``0`` and ``3`` (strictly less than ``4``), display the text "HORRIBLE!".
|
||||
|
||||
```
|
||||
input.onPinPressed("P0", () => {
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x2 = Math.random(11)
|
||||
basic.showNumber(x2, 150)
|
||||
basic.pause(3000)
|
||||
@ -51,7 +51,7 @@ input.onPinPressed("P0", () => {
|
||||
If the rating is between 4 and 7, display the text "MEDIOCRE!" **else** display the text "MATCHED!"
|
||||
|
||||
```
|
||||
input.onPinPressed("P0", () => {
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x3 = Math.random(11)
|
||||
basic.showNumber(x3, 150)
|
||||
basic.pause(3000)
|
||||
|
@ -13,7 +13,7 @@ It's a method that runs code when the user holds the GND pin with a finger of on
|
||||
## 2. Create a condition for on pin pressed ("P1").
|
||||
|
||||
```
|
||||
input.onPinPressed("P1", () => {
|
||||
input.onPinPressed(TouchPin.P1, () => {
|
||||
})
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user