lesson updates

This commit is contained in:
Michael Elliot Braun
2016-03-30 11:15:31 -07:00
70 changed files with 221 additions and 196 deletions

View File

@ -32,7 +32,7 @@ claimBall = true
<br/>
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
if (claimBall) {
pins.digitalWritePin("P0", 1)
}

View File

@ -9,7 +9,7 @@ Welcome! This [guided tutorial](https://live.microbit.co.uk/td/lessons/speed-but
```
counter = 0
fastPress = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter = counter + 1
})
```
@ -21,7 +21,7 @@ We need to know when the user has hit button `A` 15 times. The user wins when he
```
counter = 0
fastPress = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter = counter + 1
if (counter == 15 && input.runningTime() < 3500) {
}
@ -33,7 +33,7 @@ Next, if the user has won, let's set our boolean to true. This indicates that he
```
counter = 0
fastPress = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter = counter + 1
if (counter == 15 && input.runningTime() < 3500) {
fastPress = true // ***
@ -48,7 +48,7 @@ We want to set `fastPress` to false if the user was too slow. To do so, we need
```
counter = 0
fastPress = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter = counter + 1
if (counter == 15 && input.runningTime() < 3500) {
fastPress = true
@ -66,7 +66,7 @@ Now let's display if the user won or lost. To do so, we need to check the status
```
counter = 0
fastPress = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter = counter + 1
if (counter == 15 && input.runningTime() < 3500) {
fastPress = true

View File

@ -12,7 +12,7 @@ At the end of the tutorial, click `keep editing`. Your code should look like thi
```
newAction() // ***
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
if (action == 0) {
game.addScore(1) // ***
newAction() // ***
@ -30,7 +30,7 @@ input.onGesture(Gesture.Shake, () => {
newAction() // ***
}
}) // ***
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
basic.showNumber(game.score(), 150) // ***
basic.pause(2000) // ***
newAction() // ***
@ -68,12 +68,12 @@ Now let's implement `PRESS PIN 0` in the main. Create a condition of `input->on
```
// **. . .**
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
basic.showNumber(game.score(), 150) // ***
basic.pause(2000) // ***
newAction() // ***
}) // ***
input.onPinPressed("P0", () => {
input.onPinPressed(TouchPin.P0, () => {
if (action == 3) {
game.addScore(1) // ***
newAction() // ***

View File

@ -33,7 +33,7 @@ if (action == 0) {
<br />
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
if (action == 0) {
game.addScore(1)
}

View File

@ -9,7 +9,7 @@ Welcome! This [guided tutorial](/microbit/lessons/break/tutorial) will assist yo
```
count = 0
shouldBreak = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
shouldBreak = true
})
while (true) {
@ -49,7 +49,7 @@ while (true) {
basic.showNumber(count, 150)
basic.pause(1000)
}
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
}) // ***
```
@ -57,7 +57,7 @@ Next, set `shouldBreak` back to false to indicate we want to run the `while` loo
```
// **. . .**
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
shouldBreak = false // ***
})
```
@ -66,7 +66,7 @@ And now copy the code from the previous while loop into the condition of `input-
```
// **. . .**
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
shouldBreak = false
while (true) {
if (shouldBreak) {

View File

@ -9,14 +9,14 @@ Howdy! This [guided tutorial](/microbit/rxqgzy) will help you complete this acti
In this guide, you will learn how to use buttons and show text on the screen. Let's start by adding to respond **when the left button is pressed**.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
})
```
All the code inside `input->on button pressed` runs when the button is pressed. Let's add the code to show some text.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.showString("hello", 150)
})
```
@ -26,10 +26,10 @@ input.onButtonPressed("A", () => {
Let's add an event handler for Button `B`.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.showString("hello", 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
})
```
@ -38,10 +38,10 @@ input.onButtonPressed("B", () => {
Display `bye` when the `B` button is pressed.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.showString("hello", 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
basic.showString("bye", 150)
})
```

View File

@ -18,7 +18,7 @@ basic.showAnimation(`
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
```
@ -37,10 +37,10 @@ basic.showAnimation(`
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
})
```
@ -56,10 +56,10 @@ basic.showAnimation(`
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .

View File

@ -8,7 +8,7 @@ Welcome! This [guided tutorial](/microbit/lessons/comparison/tutorial) will assi
```
counter = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter = counter + 1
if (counter == 10) {
counter = 1
@ -23,7 +23,7 @@ Now let's do something special when the micro:bit reaches the number `5`. Instea
```
counter = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter = counter + 1
if (counter == 10) {
counter = 1
@ -40,7 +40,7 @@ Let's continue our plan of displaying `HALF WAY!` when `counter = 5`. To do so,
```
counter = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter = counter + 1
if (counter == 10) {
counter = 1
@ -60,7 +60,7 @@ You may notice a problem right now. When `counter = 5`, the micro:bit will show
```
counter = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter = counter + 1
if (counter == 10) {
counter = 1

View File

@ -22,7 +22,7 @@ The code under ``on button pressed("A")`` will run each time the user presses A.
```
let count_ = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count = count + 1
})
```
@ -31,7 +31,7 @@ Since the count has changed, it's time to refresh the screen display. Let's add
```
let count_1 = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count = count + 1
basic.showNumber(count, 150)
})

View File

@ -8,7 +8,7 @@ Complete the following [guided tutorial](/microbit/lessons/counter/activity) At
```
let count = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count = count + 1
basic.showNumber(count, 150)
})
@ -22,11 +22,11 @@ Let's add the code to `count` when `B` is pressed. Add an event handler with `in
```
let count1 = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count1 = count1 + 1
basic.showNumber(count1, 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
count1 = count1 - 1 // ***
basic.showNumber(count1, 150) // ***
}) // ***

View File

@ -15,14 +15,14 @@ To create a new script, go to the [Create Code](/microbit/create-code) page and
Add an event handler when button `A` is pressed.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
})
```
Create a local variable of type number `x` and set it to a random number using `math->random`. `math->random(10)` generates a random number between `0` and `10` **excluded**.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let x = Math.random(10)
})
```
@ -30,7 +30,7 @@ input.onButtonPressed("A", () => {
Show the random number on the screen.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let x1 = Math.random(10)
basic.showNumber(x1, 150)
})

View File

@ -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.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let x = Math.random(10)
basic.showNumber(x, 150)
})
@ -24,11 +24,11 @@ input.onButtonPressed("A", () => {
When button `B` is pressed, we want to clear the screen. This will make it so users can play your game over and over again! Add an event handler to handle this case.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let x1 = Math.random(10)
basic.showNumber(x1, 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
basic.clearScreen() // ***
})
```

View File

@ -13,7 +13,7 @@ At the end of the tutorial, click `keep editing`. Your code should look like thi
```
count = 0
shouldBreak = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
shouldBreak = true
})
while (true) {
@ -60,7 +60,7 @@ while (true) {
basic.showNumber(count, 150)
basic.pause(1000)
}
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
}) // ***
```
@ -68,7 +68,7 @@ Next, set `should break` back to false to indicate we want to run the `while` lo
```
// **. . .**
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
shouldBreak = false // ***
})
```
@ -77,7 +77,7 @@ And now copy the code from the previous while loop into the condition of `input-
```
// **. . .**
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
shouldBreak = false
while (true) {
if (shouldBreak) {

View File

@ -22,7 +22,7 @@ shouldBreak = false
Write the line of code to stop incrementing `count` when the button is pressed. (Hint: This will set `should break` to true).
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
shouldBreak = true
})
```

View File

@ -128,7 +128,7 @@ for (let j = 0; j < 10; j++) {
<br/>
```
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
basic.showString("WINS", 150)
basic.showNumber(wins, 150)
basic.pause(500)

View File

@ -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)
})

View File

@ -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)

View File

@ -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, () => {
})
```

View File

@ -32,7 +32,7 @@ Add a new event handler for `input->on button pressed(A)` and add the code to se
```
led.setBrightness(255)
led.plotAll()
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
led.setBrightness(64) // ***
}) // ***
```

View File

@ -13,7 +13,7 @@ At the end of the tutorial, click `keep editing`. Your code should look like thi
```
led.setBrightness(255)
led.plotAll()
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
led.setBrightness(64)
})
```
@ -27,10 +27,10 @@ What if we want to turn off all the LEDs? Let's do this by setting the brightnes
```
led.setBrightness(255)
led.plotAll()
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
led.setBrightness(64)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
led.setBrightness(0) // ***
}) // ***
```

View File

@ -126,7 +126,7 @@ for (let i4 = 0; i4 < 4; i4++) {
<br />
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
if (gameMode == 0 && playerNumber == 0) {
micro_bitTransfer.transferByte(255)
}
@ -148,7 +148,7 @@ for (let k1 = 0; k1 < 3; k1++) {
<br />
```
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
if (gameMode == 2) {
gameMode = 1
basic.plotImage(`

View File

@ -24,7 +24,7 @@ basic.forever(() => {
. . # . .
`).showImage(offset)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
offset = offset + 1
})
```
@ -47,10 +47,10 @@ basic.forever(() => {
. . # . .
`).showImage(offset)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
offset = offset + 1
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
offset = offset - 1 // ***
}) // ***
```
@ -82,10 +82,10 @@ basic.forever(() => {
. . # . .
`).showImage(offset)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
offset = offset + 1
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
offset = offset - 1
})
```

View File

@ -41,7 +41,7 @@ Write the two lines of code that cause the `variable` offset to increase by one
<br/>
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
offset = offset + 1
})
```

View File

@ -26,10 +26,10 @@ ball.setDirection(-45)
The user will control the paddle by pressing ``A`` to go up and ``B`` to go down. Let's add ``on button pressed`` event handlers to do that.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
paddle.changeYBy(-1)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
paddle.changeYBy(1)
})
```

View File

@ -42,7 +42,7 @@ led.plot(ballX, ballY)
<br/>
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
if (paddleNotUp()) {
led.unplot(0, paddleY)
paddleY = paddleY - 1
@ -56,7 +56,7 @@ input.onButtonPressed("A", () => {
<br/>
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
if (paddleNotDown()) {
led.unplot(0, paddleY)
paddleY = paddleY + 1

View File

@ -8,7 +8,7 @@ Welcome! This [guided tutorial](/microbit/lessons/return/tutorial) will help you
```
let original1 = 5
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let doubled = doubleIt_(5)
basic.showNumber(doubled, 150) // ***
})
@ -32,11 +32,11 @@ Add a condition to know when button `B` is pressed. We will use this condition i
```
let original = 5
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let one = doubleIt_(original)
basic.showNumber(one, 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
})
```

View File

@ -50,7 +50,7 @@ input.onGesture(Gesture.Shake, () => {
let offset1 = 5 * Math.random(3)
img1.showImage(offset1)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
}) // ***
```
@ -71,7 +71,7 @@ input.onGesture(Gesture.Shake, () => {
let offset2 = 5 * Math.random(3)
img2.showImage(offset2)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1 // ***
})
```
@ -93,7 +93,7 @@ input.onGesture(Gesture.Shake, () => {
let offset3 = 5 * Math.random(3)
img3.showImage(offset3)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150) // ***
basic.showNumber(wins, 150) // ***
@ -129,12 +129,12 @@ input.onGesture(Gesture.Shake, () => {
let offset4 = 5 * Math.random(3)
img4.showImage(offset4)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
}) // ***
```
@ -155,12 +155,12 @@ input.onGesture(Gesture.Shake, () => {
let offset5 = 5 * Math.random(3)
img5.showImage(offset5)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
losses = losses + 1 // ***
})
```
@ -182,12 +182,12 @@ input.onGesture(Gesture.Shake, () => {
let offset6 = 5 * Math.random(3)
img6.showImage(offset6)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
losses = losses + 1
basic.showString("WINS", 150) // ***
basic.showNumber(wins, 150) // ***
@ -213,14 +213,14 @@ input.onGesture(Gesture.Shake, () => {
let offset7 = 5 * Math.random(3)
img7.showImage(offset7)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
basic.showString("LOSSES:", 150) // ***
basic.showNumber(losses, 150) // ***
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
losses = losses + 1
basic.showString("WINS", 150)
basic.showNumber(wins, 150)

View File

@ -50,7 +50,7 @@ input.onGesture(Gesture.Shake, () => {
let offset1 = 5 * Math.random(3)
img1.showImage(offset1)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
}) // ***
```
@ -71,7 +71,7 @@ input.onGesture(Gesture.Shake, () => {
let offset2 = 5 * Math.random(3)
img2.showImage(offset2)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1 // ***
})
```
@ -93,7 +93,7 @@ input.onGesture(Gesture.Shake, () => {
let offset3 = 5 * Math.random(3)
img3.showImage(offset3)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150) // ***
basic.showNumber(wins, 150) // ***
@ -129,12 +129,12 @@ input.onGesture(Gesture.Shake, () => {
let offset4 = 5 * Math.random(3)
img4.showImage(offset4)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
}) // ***
```
@ -155,12 +155,12 @@ input.onGesture(Gesture.Shake, () => {
let offset5 = 5 * Math.random(3)
img5.showImage(offset5)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
losses = losses + 1 // ***
})
```
@ -182,12 +182,12 @@ input.onGesture(Gesture.Shake, () => {
let offset6 = 5 * Math.random(3)
img6.showImage(offset6)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
losses = losses + 1
basic.showString("WINS", 150) // ***
basic.showNumber(wins, 150) // ***
@ -213,14 +213,14 @@ input.onGesture(Gesture.Shake, () => {
let offset7 = 5 * Math.random(3)
img7.showImage(offset7)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
basic.showString("LOSSES:", 150) // ***
basic.showNumber(losses, 150) // ***
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
losses = losses + 1
basic.showString("WINS", 150)
basic.showNumber(wins, 150)

View File

@ -34,7 +34,7 @@ input.onGesture(Gesture.Shake, () => {
`)
img1.plotFrame(Math.random(3))
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1) // ***
}) // ***
```
@ -54,7 +54,7 @@ input.onGesture(Gesture.Shake, () => {
`)
img2.plotFrame(Math.random(3))
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
basic.showString("WINS: ", 150) // ***
basic.showNumber(game.score(), 150) // ***

View File

@ -27,7 +27,7 @@ Now let's add to this by creating a condition for on button pressed `A` before t
```
rotating = true
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
}) // ***
while (rotating) {
basic.showAnimation(`
@ -48,7 +48,7 @@ Now that we have the on button pressed condition, let's make the animation stop
```
rotating = true
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
rotating = false // ***
}) // ***
while (rotating) {

View File

@ -30,7 +30,7 @@ Now let's add to this by creating a condition for on button pressed `A` before t
```
rotating = true
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
}) // ***
while (rotating) {
basic.showAnimation(`
@ -52,7 +52,7 @@ Now that we have the on button pressed condition, let's make the animation stop
```
rotating = true
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
rotating = false // ***
}) // ***
while (rotating) {

View File

@ -88,7 +88,7 @@ levelTime = 0
<br/>
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let temp = math.abs(person.dirX) * (-1)
// {stcode}
// MACRO: stcode
@ -104,7 +104,7 @@ input.onButtonPressed("A", () => {
<br/>
```
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
let temp1 = math.abs(person.dirX)
// {stcode}
// MACRO: stcode

View File

@ -32,7 +32,7 @@ basic.showAnimation(`
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.clearScreen() // ***
}) // ***
```

View File

@ -14,7 +14,7 @@ basic.showAnimation(`
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
```
@ -31,10 +31,10 @@ basic.showAnimation(`
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
})
```
@ -52,10 +52,10 @@ basic.showAnimation(`
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .

View File

@ -1,6 +1,6 @@
# set brightness challenges
These challenges will allow you to change the brightness of the micro:bit. #docs
These challenges will allow you to change the brightness of the micro:bit. docs
**Challenge 0**
@ -11,7 +11,7 @@ These challenges will allow you to change the brightness of the micro:bit. #docs
```
led.setBrightness(255)
led.plotAll()
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
led.setBrightness(64)
})
```
@ -25,10 +25,10 @@ What if we want to turn off all the LEDs? Let's do this by setting the brightnes
```
led.setBrightness(255)
led.plotAll()
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
led.setBrightness(64)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
}) // ***
```
@ -39,10 +39,10 @@ Inside of the condition `input->on button pressed("B")`, add `led->set brightnes
```
led.setBrightness(255)
led.plotAll()
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
led.setBrightness(64)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
led.setBrightness(0) // ***
})
```

View File

@ -30,7 +30,7 @@ basic.showAnimation(`
# . . . # . . . . .
. # # # . . . . . .
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
}) // ***
```
@ -48,7 +48,7 @@ basic.showAnimation(`
# . . . # . . . . .
. # # # . . . . . .
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
. # . # .
. # . # .

View File

@ -13,7 +13,7 @@ At the end of the tutorial, click `keep editing`. Your code should look like thi
```
let counter = 0
let fastPress = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter = counter + 1
})
```
@ -25,7 +25,7 @@ We need to know when the user has hit button `A` 15 times. The user wins when he
```
let counter1 = 0
let fastPress1 = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter1 = counter1 + 1
if (counter1 == 15 && input.runningTime() < 5000) {
}
@ -37,7 +37,7 @@ Next, if the user has won, let's set our boolean to true. This indicates that he
```
let counter2 = 0
let fastPress2 = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter2 = counter2 + 1
if (counter2 == 15 && input.runningTime() < 5000) {
fastPress2 = true // ***
@ -52,7 +52,7 @@ We want to set `fastPress` to false if the user was too slow. To do so, we need
```
let counter3 = 0
let fastPress3 = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter3 = counter3 + 1
if (counter3 == 15 && input.runningTime() < 5000) {
fastPress3 = true
@ -72,7 +72,7 @@ Now let's display if the user won or lost. To do so, we need to check the status
```
let counter4 = 0
let fastPress4 = false
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
counter4 = counter4 + 1
if (counter4 == 15 && input.runningTime() < 5000) {
fastPress4 = true

View File

@ -22,7 +22,7 @@ let count = 0
```
let count_ = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count_ = count_ + 1
basic.showNumber(count_, 100)
})
@ -38,7 +38,7 @@ After two button presses, **count** will be equal to 2.
```
count_ = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count_ = count_ + 1
basic.showNumber(count_, 100)
})

View File

@ -24,7 +24,7 @@ let count = 0
```
let count_ = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count_ = count_ + 1
basic.showNumber(count_, 100)
})
@ -38,7 +38,7 @@ input.onButtonPressed("A", () => {
```
count_ = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count_ = count_ + 1
basic.showNumber(count_, 100)
})

View File

@ -13,10 +13,10 @@ At the end of the tutorial, click `keep editing`. Your code should look like thi
```
initializeGame()
playLevel()
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
selectHat()
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
chooseHat()
})
```

View File

@ -46,7 +46,7 @@ Write the code that displays the next letter of the string in "cup select" when
<br/>
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
index = index + 1
if (index > 2) {
index = 0

View File

@ -12,7 +12,7 @@ At the end of the tutorial, click `keep editing`. Your code should look like thi
```
let inital = 5
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let doubled1 = double(initial)
basic.showNumber(doubled1, 150) // ***
})
@ -40,11 +40,11 @@ Add a condition for when button `B` is pressed. We will use this condition in th
```
initial = 5
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let doubled = double(initial)
basic.showNumber(doubled, 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
}) // ***
```

View File

@ -21,7 +21,7 @@ let x = 5
<br/>
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
})
```

View File

@ -28,7 +28,7 @@ basic.showLeds(`
. . # . .
. . # . .
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
})
```
@ -42,7 +42,7 @@ basic.showLeds(`
. . # . .
. . # . .
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let random = Math.random(2)
})
```
@ -57,7 +57,7 @@ basic.showLeds(`
. . # . .
. . # . .
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let random1 = Math.random(2)
if (random1 == 0) {
basic.showString("TRUTH", 150)
@ -79,7 +79,7 @@ basic.showLeds(`
. . # . .
. . # . .
`, 400)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let random2 = Math.random(2)
if (random2 == 0) {
basic.showString("TRUTH", 150)

View File

@ -18,7 +18,7 @@ basic.plotImage(`
. . # . .
. . # . .
`)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let random = Math.random(2)
if (random == 0) {
basic.showString("TRUTH", 150)
@ -47,7 +47,7 @@ basic.plotImage(`
. . # . .
. . # . .
`)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let random1 = Math.random(3) // ***
if (random1 == 0) {
basic.showString("TRUTH", 150)
@ -76,7 +76,7 @@ basic.plotImage(`
. . # . .
. . # . .
`)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
let random2 = Math.random(3)
if (random2 == 0) {
basic.showString("TRUTH", 150) // ***

View File

@ -10,14 +10,14 @@ This [guided tutorial](/microbit/lessons/typing-game/tutorial) will teach you ho
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
index = 0
name = ""
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
led.showString(alphabet.substr(index, 1), 0)
index = index + 1
})
if (index > 25) {
index = 0
}
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
name = name.concat(alphabet.substr(index - 1, 1))
})
input.onGesture(Gesture.Shake, () => {
@ -33,14 +33,14 @@ After you have shown the string in the condition `on shake`, make the name varia
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
index = 0
name = ""
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
led.showString(alphabet.substr(index, 1), 0)
index = index + 1
})
if (index > 25) {
index = 0
}
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
name = name.concat(alphabet.substr(index - 1, 1))
})
input.onGesture(Gesture.Shake, () => {
@ -57,14 +57,14 @@ After you have cleared the name variable to hold nothing, make `index := 0` so t
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
index = 0
name = ""
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
led.showString(alphabet.substr(index, 1), 0)
index = index + 1
})
if (index > 25) {
index = 0
}
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
name = name.concat(alphabet.substr(index - 1, 1))
})
input.onGesture(Gesture.Shake, () => {

View File

@ -18,7 +18,7 @@ Now we need to reply after someone asks Micro a yes or no question. We want to
```
basic.showString("ASK ME A QUESTION", 150)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.showString("YES", 150) // ***
}) // ***
```
@ -33,10 +33,10 @@ What if Micro's answer to the question is no? Let's have `NO` be displayed when
```
basic.showString("ASK ME A QUESTION", 150)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.showString("YES", 150)
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
basic.showString("NO", 150) // ***
}) // ***
```