Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
58f79ea617 | |||
ed6d343992 | |||
92b46d5c7b | |||
9cf7f08ae2 | |||
3b05b8f2f6 | |||
774d614d79 | |||
545f715eeb | |||
45b480c6dd |
@ -39,4 +39,6 @@ screen, then a smiley again -- it never stops! (That's because of the
|
||||
Click **Compile** to move your program to the BBC micro:bit!
|
||||
Make sure to follow the instructions.
|
||||
|
||||
## [NEXT: THE SCREEN](/getting-started/screen)
|
||||
### ~button /getting-started/screen
|
||||
NEXT: THE SCREEN
|
||||
### ~
|
@ -76,4 +76,6 @@ your handshake to make it happen!
|
||||
|
||||
## ~
|
||||
|
||||
## [NEXT: SHAKE](/getting-started/shake)
|
||||
### ~button /getting-started/shake
|
||||
NEXT: SHAKE
|
||||
### ~
|
@ -73,4 +73,6 @@ input.onButtonPressed(Button.AB, () => {
|
||||
|
||||
Flip until your thumbs get tired!
|
||||
|
||||
## [NEXT: ROCK PAPER SCISSORS](/getting-started/rock-paper-scissors)
|
||||
### ~button /getting-started/rock-paper-scissors
|
||||
NEXT: ROCK PAPER SCISSORS
|
||||
### ~
|
||||
|
@ -200,4 +200,6 @@ input.onButtonPressed(Button.B, () => {
|
||||
```
|
||||
Click **Compile** to move your program to the BBC micro:bit!
|
||||
|
||||
## [NEXT: PROJECTS!](/projects)
|
||||
### ~button /projects
|
||||
NEXT: PROJECTS!
|
||||
### ~
|
||||
|
@ -93,4 +93,6 @@ You can find the ``show leds`` block in the **Basic** part of the editor.
|
||||
|
||||
#### ~
|
||||
|
||||
## [NEXT: BUTTONS](/getting-started/buttons)
|
||||
### ~button /getting-started/buttons
|
||||
NEXT: BUTTONS
|
||||
### ~
|
@ -19,4 +19,6 @@ input.onGesture(Gesture.Shake, () => {
|
||||
```
|
||||
Click **Compile** to move your program to the BBC micro:bit!
|
||||
|
||||
## [NEXT: COIN FLIPPER GAME](/getting-started/coin-flipper)
|
||||
### ~button /getting-started/coin-flipper
|
||||
NEXT: COIN FLIPPER GAME
|
||||
### ~
|
||||
|
@ -18,10 +18,9 @@ bluetooth.uartRead("");
|
||||
### Example: Starting the Bluetooth UART service and then reading data received from another device which is terminated by ":" character and then displaying it
|
||||
|
||||
```blocks
|
||||
let uart_data: string = "";
|
||||
let uart_data = "";
|
||||
let connected = 0;
|
||||
basic.showString("UART");
|
||||
bluetooth.startUartService();
|
||||
bluetooth.onBluetoothConnected(() => {
|
||||
basic.showString("C");
|
||||
connected = 1;
|
||||
|
@ -27,7 +27,6 @@ bluetooth.onBluetoothDisconnected(() => {
|
||||
basic.showString("D");
|
||||
connected = 0;
|
||||
});
|
||||
bluetooth.startUartService();
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
if (connected == 1) {
|
||||
bluetooth.uartWrite("HELLO");
|
||||
|
@ -1,15 +1,25 @@
|
||||
# In Background
|
||||
# Run In Background
|
||||
|
||||
Run code in the background as a separate process or thread; for more information on this advanced construct, see [the micro:bit - a reactive system](/device/reactive).
|
||||
Run part of a program while the rest of it is doing something else.
|
||||
|
||||
```sig
|
||||
control.inBackground(() => {
|
||||
})
|
||||
```
|
||||
|
||||
### ~hint
|
||||
|
||||
For more information, read
|
||||
[The micro:bit - a reactive system](/device/reactive).
|
||||
It is pretty advanced!
|
||||
|
||||
### ~
|
||||
|
||||
### Example
|
||||
|
||||
The example below shows how a background process can be used to display the current value of the global variable `num`, while code (like the `on button pressed` handler) can change the value of the variable.
|
||||
This program shows how running in the background can say what is
|
||||
stored in a variable like `num`, while another part (``on button pressed``)
|
||||
changes what is stored there.
|
||||
|
||||
```blocks
|
||||
let num = 0
|
||||
@ -24,7 +34,8 @@ input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
```
|
||||
|
||||
The code below using the `forever` loop is equivalent to the code above
|
||||
This program does the same thing, but in a more usual way,
|
||||
with a ``forever`` loop.
|
||||
|
||||
```blocks
|
||||
let num = 0
|
||||
@ -36,20 +47,8 @@ input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
```
|
||||
|
||||
### Contention for the LED display
|
||||
|
||||
If you have multiple processes that each show something on the LED screen, you may get unexpected results. Try, for example:
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showNumber(6789, 150)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showNumber(2, 150)
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[while](/blocks/loops/while), [forever](/reference/basic/forever), [on button pressed](/reference/input/on-button-pressed)
|
||||
[while](/blocks/loops/while), [forever](/reference/basic/forever),
|
||||
[on button pressed](/reference/input/on-button-pressed)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.2.178",
|
||||
"version": "0.2.180",
|
||||
"description": "BBC micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -29,6 +29,6 @@
|
||||
"typescript": "^1.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.2.188"
|
||||
"pxt-core": "0.2.190"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user