Compare commits

...

39 Commits

Author SHA1 Message Date
4d1f157ed3 0.0.16 2016-03-30 10:50:22 -07:00
0500da7a72 Bump kindscript to 0.1.123 2016-03-30 10:50:20 -07:00
0d321114c0 updated color 2016-03-30 10:46:40 -07:00
8f61570158 0.0.15 2016-03-29 23:09:21 -07:00
06916c4f82 Bump kindscript to 0.1.121 2016-03-29 23:09:19 -07:00
850c313c5d batch replace onButtonPressed(Button... 2016-03-29 21:17:57 -07:00
1f7e0b0f79 smoothly transition back to non-tilted 2016-03-29 21:14:27 -07:00
0e816f2398 moved remaining quizzes 2016-03-29 15:21:17 -07:00
c6e2391bcd Merge branch 'master' of https://github.com/Microsoft/kindscript-microbit 2016-03-29 15:14:40 -07:00
00adabe441 file management quizzes 2016-03-29 15:14:16 -07:00
3ccec89f33 updated demo program 2016-03-29 14:19:56 -07:00
d5488a3ae8 0.0.14 2016-03-29 13:55:36 -07:00
8a14a95fcc Bump kindscript to 0.1.119 2016-03-29 13:55:34 -07:00
d0fcd5f400 0.0.13 2016-03-29 13:47:07 -07:00
491c5faaf6 0.0.12 2016-03-29 13:39:32 -07:00
8179e38e41 Bump kindscript to 0.1.118 2016-03-29 13:39:30 -07:00
d9c51b5fd5 docs update 2016-03-29 13:17:00 -07:00
8cbd8e5a74 quiz updates 2016-03-29 13:13:18 -07:00
5a8a5f82c9 Merge branch 'master' of https://github.com/Microsoft/kindscript-microbit 2016-03-29 11:58:49 -07:00
c43088c099 quiz update 2016-03-29 11:57:50 -07:00
816d738390 0.0.11 2016-03-29 11:35:17 -07:00
3e133aa66e Bump kindscript to 0.1.117 2016-03-29 11:35:14 -07:00
a471c2cb1a 0.0.10 2016-03-29 08:41:30 -07:00
a5826540fa Bump kindscript to 0.1.115 2016-03-29 08:41:29 -07:00
1768881719 Simplify travis instructions 2016-03-29 08:26:18 -07:00
365c95b33d 0.0.9 2016-03-28 23:29:26 -07:00
d05fa9f4cb Bump kindscript to 0.1.114 2016-03-28 23:29:25 -07:00
acb0c66e85 some edits to about 2016-03-28 23:18:27 -07:00
a705b74fab 0.0.8 2016-03-28 22:28:10 -07:00
85d406661a 0.0.7 2016-03-28 22:16:20 -07:00
8fa190b209 Bump kindscript to 0.1.113 2016-03-28 22:16:18 -07:00
664b841b1c updated enum annotation to support patching 2016-03-28 22:16:07 -07:00
715de4dff9 Merge branch 'master' of https://github.com/Microsoft/kindscript-microbit 2016-03-28 22:15:14 -07:00
514e7cf1db Target stuff now under /sim/ on localhost 2016-03-28 21:38:48 -07:00
c9f927b0bf no hats on advanced events 2016-03-28 20:56:09 -07:00
0802b509c4 0.0.6 2016-03-28 19:45:31 -07:00
383bdc491d Bump kindscript to 0.1.111 2016-03-28 19:45:29 -07:00
ffbbf56c1c 0.0.5 2016-03-28 19:03:58 -07:00
718ec896ab Remove private from package 2016-03-28 19:03:45 -07:00
122 changed files with 504 additions and 377 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ tmp/
*.ts.new
*.tgz
temp/
*.db

View File

@ -2,8 +2,6 @@ language: node_js
node_js:
- "5.7.0"
script:
- "npm update"
- "node node_modules/kindscript/built/kind.js buildtarget"
- "node node_modules/kindscript/built/kind.js travis"
- "node node_modules/kindscript/built/kind.js uploaddoc"
sudo: false

View File

@ -1,14 +1,14 @@
# About
The [BBC micro:bit](https://www.microbit.co.uk) is a [pocket-size computer](/device) with 25 LEDs, Bluetooth and sensors that can be programmed by anyone.
The BBC micro:bit was made possible by [a number of partners!](https://www.microbit.co.uk/partners)
The [BBC micro:bit](https://www.microbit.co.uk) is a [pocket-size computer](/device) with a 5x5 display of 25 LEDs, Bluetooth and sensors that can be programmed by anyone.
The BBC micro:bit was made possible by many [partners](https://www.microbit.co.uk/partners).
The micro:bit provides a fun introduction to programming and making switch on, program it to do something fun wear it, customize it.
Just like Arduino, the micro:bit can be connected to and interact with sensors, displays, and other devices.
## Block Editor or JavaScript
## Blocks or JavaScript
The student can program the BBC micro:bit using a Block Editor or JavaScript.
The student can program the BBC micro:bit using [visual blocks](http://www.github.com/Google/blockly) or JavaScript.
```blocks
basic.showString("BBC micro:bit!");
@ -36,6 +36,14 @@ input.onButtonPressed(Button.A, () => {
# . . . #
. # # # .`);
});
input.onButtonPressed(Button.B, () => {
basic.showLeds(`
. # . # .
# . # . #
# . . . #
. # . # .
. . # . .`);
});
input.onGesture(Gesture.Shake, () => {
basic.showLeds(`
. . . . .
@ -44,18 +52,12 @@ input.onGesture(Gesture.Shake, () => {
. # # # .
# . . . #`);
});
basic.showString("BBC micro:bit");
```
To run a student's project in the web browser, KindScript compiles it into JavaScript, the scripting language built into all web browsers.
C++ and Touch Develop Libraries
The C++ micro:bit library, created at Lancaster University, provides access to the hardware functions of the micro:bit, as well as a set of helper functions (such as displaying a number/image/string on the LED screen). The Touch Develop micro:bit library mirrors the functions of the C++ library. When a Touch Develop script is compiled to C++, the calls to Touch Develop micro:bit functions are replaced with calls to the corresponding C++ functions.
Above, see the mapping from the Touch Develop "show number" function to its corresponding the C++ function.
## C++ Runtime
The C++ BBC micro:bit library, created at [Lancaster University](http://www.lancaster.ac.uk/), provides access to the hardware functions of the micro:bit,
as well as a set of helper functions (such as displaying a number/image/string on the LED screen).
The JavaScript micro:bit library mirrors the functions of the C++ library.
When code is compiled to C++, the calls to JavaScript micro:bit functions are replaced with calls to the corresponding C++ functions.
When code is compiled to ARM machine code, the calls to JavaScript micro:bit functions are replaced with calls to the corresponding C++ functions.

View File

@ -52,7 +52,7 @@ The first job of the scheduler is to allow multiple *subprograms* to be queued u
```
export function countButtonPresses() {
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count = count + 1
})
basic.forever(() => {
@ -65,7 +65,7 @@ export function countButtonPresses() {
The program above contains three statements that execute in order from top to bottom. The first statement
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count = count + 1
})
```
@ -132,14 +132,14 @@ As a result, you can easily add a new capability to the micro:bit by just adding
```
export function countButtonPressesWithReset() {
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count = count + 1
})
basic.forever(() => {
basic.showNumber(count, 150)
})
count = 0
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
count = 0
})
}

View File

@ -32,5 +32,10 @@ basic.showString("Hi")
![](/static/mb/lessons/answering-machine-2.png)
![](/static/mb/blocks/lessons/answering-machine-5.png)
```blocks
basic.showString("Z")
```

View File

@ -10,7 +10,10 @@ Answers will vary. In general, plot refers to the code that turns on a specific
## 2. Draw which LED is ON after running this code
![](/static/mb/blocks/lessons/blink-6.png)
```blocks
led.plot(2, 2)
```
![](/static/mb/lessons/blink-0.png)
@ -18,7 +21,10 @@ By default, the position of an LED on *Blink Tutorial* is set to the centre of t
## 3. Draw which LED is ON after running this code
![](/static/mb/blocks/lessons/blink-7.png)
```blocks
led.plot(0, 0)
```
![](/static/mb/lessons/blink-1.png)
@ -29,7 +35,10 @@ This code turns on specific LED. Plot turns on the specified LED on the LED scre
## 4. Draw which LED is ON after running this code
![](/static/mb/blocks/lessons/blink-8.png)
```blocks
led.plot(4, 4)
```
![](/static/mb/lessons/blink-2.png)

View File

@ -12,23 +12,34 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
## 1. Describe what `plot` does?
<br/>
## 2. Draw which LED is ON after running this code
![](/static/mb/blocks/lessons/blink-6.png)
```blocks
led.plot(2, 2)
```
![](/static/mb/empty-microbit.png)
## 3. Draw which LED is ON after running this code
![](/static/mb/blocks/lessons/blink-7.png)
```blocks
led.plot(0, 0)
```
![](/static/mb/empty-microbit.png)
## 4. Draw which LED is ON after running this code
![](/static/mb/blocks/lessons/blink-8.png)
```blocks
led.plot(4, 4)
```
![](/static/mb/empty-microbit.png)

View File

@ -14,11 +14,9 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
Gets the compass heading of the micro:bit in degrees
<br/>
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
<br/>
```
let degrees = input.compassHeading()
@ -26,7 +24,6 @@ let degrees = input.compassHeading()
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the micro:bit
<br />
```
if (degrees < 45) {
@ -34,9 +31,8 @@ if (degrees < 45) {
}
```
## 3. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the micro:bit
## 4. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the micro:bit
<br />
```
if (degrees < 135) {
@ -44,9 +40,8 @@ if (degrees < 135) {
}
```
## 3. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the micro:bit
## 5. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the micro:bit
<br />
```
if (degrees < 225) {

View File

@ -12,21 +12,15 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
## 1. What is the purpose of the 'compass heading' block?
<br/>
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
<br/>
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the micro:bit
<br />
## 3. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the micro:bit
## 4. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the micro:bit
<br />
## 3. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the micro:bit
## 5. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the micro:bit
<br />

View File

@ -24,7 +24,7 @@ We create a **variable**, `count` to keep track of the current count. The number
```
let count_ = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count_ = count_ + 1
basic.showNumber(count, 150)
})
@ -40,7 +40,7 @@ We are only pressing on button pressed once. So the number to display on the mic
```
count_ = 0
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
count_ = count_ + 1
basic.showNumber(count_, 100)
})

View File

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

View File

@ -10,13 +10,15 @@ Pause program execution for the specified number of milliseconds.
## 2. Write the code that leaves an image on the screen for 1 second (1000 milliseconds)
<br/>
![](/static/mb/blocks/lessons/flashing-heart-5.jpg)
```blocks
basic.pause(1000)
```
## 3. Write the code that leaves an image on the screen for 1.5 seconds (1500 milliseconds)
![](/static/mb/blocks/lessons/flashing-heart-6.jpg)
```blocks
basic.pause(1500)
```
<br/>

View File

@ -12,19 +12,14 @@ Answer the questions while completing the activity. Pay attention to the dialogu
## 1. Describe what `pause` does?
<br/>
<br/>
## 2. Write the code that leaves an image on the screen for 1 second (1000 milliseconds)
<br/>
<br/>
## 3. Write the code that leaves an image on the screen for 1.5 seconds (1500 milliseconds)
<br/>
<br/>

View File

@ -13,7 +13,7 @@ Answers may vary. Generally, on button pressed run code when an input button is
Write the line of code that creates a condition when the BBC micro:bit button A is pressed.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
})
```

View File

@ -14,27 +14,33 @@ It's a method that runs code when the user holds the GND pin with a finger of on
Create a condition for `on pin pressed (P0)`.
![](/static/mb/blocks/lessons/love-meter-0.jpg)
```blocks
input.onPinPressed(TouchPin.P0, () => {
})
```
## 3. What does this line of code doing?
![](/static/mb/blocks/lessons/love-meter-6.png)
```blocks
let x = Math.random(9)
```
<br/>
It stores random number between 0 and 9 then stores that number in a variable.
## 4. Why do you have to add 1 to variable x?
![](/static/mb/blocks/lessons/love-meter-7.png)
<br/>
```blocks
let item = 0;
item = 0;
basic.showNumber(item + 1);
```
You have to add 1 if you want to generate a random number between 1 and 10 .
## 5. Why do you have to hold ground (GND) to make this work on the micro:bit?
<br/>
You have told GND to complete the circuit.

View File

@ -12,25 +12,28 @@ Answer the questions below while completing the activity. Pay attention to the d
## 1. Describe what `on pin pressed` does?
<br/>
## 2. Create a condition for on pin pressed (P0).
<br/>
## 3. Describe what this line of code does?
![](/static/mb/blocks/lessons/love-meter-6.png)
```blocks
let x = Math.random(9)
```
<br/>
## 4. Describe what adding 1 to variable x does?
![](/static/mb/blocks/lessons/love-meter-7.png)
```blocks
let item = 0;
item = 0;
basic.showNumber(item + 1);
```
<br/>
## 5. Describe why you must hold ground (GND) before pressing (P0) to run a program using `on pin pressed(P0)` on the micro:bit
<br/>

View File

@ -12,13 +12,31 @@ This function turns off all the LED lights on the LED screen.
![](/static/mb/blocks/lessons/screen-wipe-4.png)
![](/static/mb/blocks/lessons/screen-wipe-5.png)
```blocks
basic.showLeds(`
. # . # .
. # . # .
. . # . .
# . . . #
. # # # .
`)
```
## 3. Write the condition that will detect on button A pressed
![](/static/mb/blocks/lessons/screen-wipe-6.png)
```blocks
input.onButtonPressed(Button.A, () => {
})
```
## 4. Write the code that will clear show LEDS from the screen after pressing button A
![](/static/mb/blocks/lessons/screen-wipe-7.png)
```blocks
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
```

View File

@ -12,19 +12,18 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
## 1. Describe what "clear screen" does?
<br/>
## 2. Write the code that clears an image from the screen
![](/static/mb/blocks/lessons/screen-wipe-4.png)
<br/>
## 3. Write the condition that will detect on button A pressed
<br/>
## 4. Write the code that will clear show LEDS from the screen after pressing button A
<br/>

View File

@ -16,13 +16,36 @@ The extra empty image with show LED creates a blinking smiley, allowing the micr
## 3. Draw the image created with this code
![](/static/mb/blocks/lessons/smiley-3.png)
```blocks
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
```
![](/static/mb/blocks/lessons/smiley-4.png)
## 4. Write the code to make this image
![](/static/mb/blocks/lessons/smiley-5.png)
```blocks
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
```
![](/static/mb/blocks/lessons/smiley-6.png)

View File

@ -10,27 +10,45 @@ Use the hints in the [Smiley](/microbit/lessons/smiley/activity) activity to ans
## 1. Describe what `show LEDs` does
<br/>
<br/>
## 2. Why is there an extra empty frame after the smiley face?
![](/static/mb/lessons/smiley-0.png)
<br/>
## 3. Draw the image created with this code
![](/static/mb/blocks/lessons/smiley-3.png)
```blocks
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
```
![](/static/mb/empty-microbit.png)
<br/>
## 4. Draw the images created with this code
![](/static/mb/blocks/lessons/smiley-5.png)
```blocks
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
```
![](/static/mb/lessons/looper-3.png)

View File

@ -10,7 +10,17 @@ Run code in the background forever (answers may vary).
## 2. Draw the picture that will be produced with this code
![](/static/mb/blocks/lessons/snowflake-fall-4.png)
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
});
```
![](/static/mb/lessons/flashing-heart-0.png)

View File

@ -10,21 +10,31 @@ Use the hints in the [snowflake fall activity](/microbit/lessons/snowflake-fall/
## 1. What is a forever loop?
<br />
## 2. Draw the picture that will be produced with this code
![](/static/mb/blocks/lessons/snowflake-fall-4.png)
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
});
```
![](/static/mb/empty-microbit.png)
<br/>
## 3. Write the code for a forever loop and show LEDS for these images!
![](/static/mb/lessons/snowflake-fall-0.png)
<br/>
## 4. Write the code for a forever loop and show LEDS for these images!
@ -32,5 +42,5 @@ Use the hints in the [snowflake fall activity](/microbit/lessons/snowflake-fall/
![](/static/mb/lessons/snowflake-fall-2.png)
<br/>

View File

@ -37,7 +37,7 @@ let num = 0
basic.forever(() => {
basic.showNumber(num, 150)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
num = num + 1
})
```

View File

@ -101,13 +101,13 @@ for (let i3 = 0; i3 < 5; i3++) {
Local scope allows you to use the same variable name in different parts of a program without concern about interference (as with variables with global scope). Here's the Touch Develop program that implements the "X" program without interference:
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
for (let i4 = 0; i4 < 5; i4++) {
led.plot(i4, i4)
basic.pause(1000)
}
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
for (let i5 = 0; i5 < 5; i5++) {
led.plot(4 - i5, i5)
basic.pause(1000)

View File

@ -19,7 +19,7 @@ control.inBackground(() => {
basic.pause(100)
}
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
num++;
})
```
@ -31,7 +31,7 @@ let num = 0
basic.forever(() => {
basic.showNumber(num, 150)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
num++;
})
```
@ -44,7 +44,7 @@ If you have multiple processes that each show something on the LED screen, you m
basic.forever(() => {
basic.showNumber(6789, 150)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.showNumber(2, 150)
})
```

View File

@ -15,7 +15,7 @@ The code below shows a simple game where the user gets to press the button ``A``
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)

View File

@ -27,7 +27,7 @@ let img = images.createImage(`
. . . . .
`)
img.showImage(0)
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
img.clear()
img.showImage(0)
})

View File

@ -13,7 +13,7 @@ The game library supports simple single-player time-based games. The player has
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)

View File

@ -15,7 +15,7 @@ The code below shows a simple game where the user gets to press the button ``A``
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)

View File

@ -13,7 +13,7 @@ The game library supports simple single-player time-based games. The general goa
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)

View File

@ -98,10 +98,10 @@ This program will record the current acceleration measured on `x` when you press
```
let accelerations = (<number[]>[])
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
accelerations.push(input.acceleration("x"))
})
input.onButtonPressed("B", () => {
input.onButtonPressed(Button.B, () => {
for (let i1 = 0; i1 < accelerations.length; i1++) {
basic.showString(accelerations[i1].toString(), 150)
}

View File

@ -9,7 +9,7 @@ An event handler is code that is associated with a particular event, such as "bu
Functions named "on <event>" create an association between an event and the event handler code. For example, the following code registers the event handler (the code between the `do` and `end` keywords) with the event of a press of button A:
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.showString("hello", 150)
})
```
@ -21,7 +21,7 @@ After this code executes, then whenever button A is pressed in the future, the s
Once you have registered an event handler for an event, like above, that event handler is active for the rest of the program execution. If you want to stop the string "hello" from printing each time button A is pressed then you need to arrange for the following code to execute:
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
})
```
@ -32,10 +32,10 @@ The above code associated an event handler that does nothing with the event of a
The above example also illustrates that there is only one event handler for each event. What is the result of the following code?
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.showString("hello", 150)
})
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.showString("goodbye", 150)
})
```
@ -43,7 +43,7 @@ input.onButtonPressed("A", () => {
The answer is that whenever button A is pressed, the string "goodbye" will be printed. If you want both the strings "hello" and "goodbye" to be printed, you need to write the code like this:
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
basic.showString("hello", 150)
basic.showString("goodbye", 150)
})

View File

@ -9,7 +9,7 @@ The game library supports simple single-player time-based games. The player has
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)

View File

@ -15,7 +15,7 @@ The code below shows a simple game where the user gets to press the button ``A``
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)

View File

@ -15,7 +15,7 @@ The code below shows a simple game where the user gets to press the button ``A``
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)

View File

@ -15,7 +15,7 @@ The code below shows a simple game where the user gets to press the button ``A``
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)

View File

@ -13,7 +13,7 @@ The game library supports simple single-player time-based games. The general goa
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
```
input.onButtonPressed("A", () => {
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)

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

Some files were not shown because too many files have changed in this diff Show More