2.1.28, initiation update to PXT v5.28.24 (#54)

This commit is contained in:
Amerlander
2019-12-02 05:58:26 +01:00
committed by Peli de Halleux
parent 38a964516e
commit 5c114a0c57
1261 changed files with 50692 additions and 21604 deletions

View File

@ -0,0 +1,29 @@
# assert
Stop the program if the assertion condition is false.
```sig
control.assert(false)
```
You can insist that your program will stop at an assert block if a certain condition you check is false. The error number in the assert is written to the serial port with a failure message.
## Parameters
* **cond**: a [boolean](/types/boolean) where true means everything is ok or false which means, stop the program!
* **msg**: an optional [string](/types/string) with a message describing the failed assertion.
## Example
Stop the program if a sensor connected to pin `P0` sends a low (`0`) signal.
```blocks
basic.forever(() => {
control.assert(pins.digitalReadPin(DigitalPin.P0) == 1)
basic.pause(1000)
})
```
## See also
[panic](/reference/control/panic)

View File

@ -1,6 +1,6 @@
# Device Name
Gets a friendly name for the device derived from the its serial number.
Make a friendly name for the device based on its serial number.
```sig
control.deviceName();

View File

@ -7,15 +7,15 @@ control.inBackground(() => {
})
```
### ~hint
## ~hint
For more information, read
[The @boardname@ - a reactive system](/device/reactive).
It is pretty advanced!
### ~
## ~
### Example
## Example
This program shows how running in the background can say what is
stored in a variable like `num`, while another part (``on button pressed``)
@ -25,7 +25,7 @@ changes what is stored there.
let num = 0
control.inBackground(() => {
while (true) {
basic.showNumber(num, 150)
basic.showNumber(num)
basic.pause(100)
}
})
@ -40,14 +40,14 @@ with a ``forever`` loop.
```blocks
let num = 0
basic.forever(() => {
basic.showNumber(num, 150)
basic.showNumber(num)
})
input.onButtonPressed(Button.A, () => {
num++;
})
```
### See also
## See also
[while](/blocks/loops/while), [forever](/reference/basic/forever),
[on button pressed](/reference/input/on-button-pressed)

View File

@ -0,0 +1,40 @@
# panic
Display an error number and stop the program.
```sig
control.panic(0)
```
If your board has some way to display error information, ``||control:panic||`` will work
with it to show error numbers.
Your program stops when you use ``||control:panic||``. Use this when you think something bad enough has
happened and your program can't run properly anymore.
## Parameters
* **code**: an error [number](/types/number) you match to an error situation in your program.
### ~hint
**System error codes**
The @boardname@ has error codes reserved for use by the system software. The ```panic()``` function is for advanced usage only. You must carefully chose an error code that doesn't match one currently used by the @boardname@ system.
### ~
## Example
Send a 'code red' error that you created to the error display if the input from pin `P0` is lower than `10`.
```blocks
let codeRed = 1110;
let codeBlue = 1111;
if (pins.analogReadPin(AnalogPin.P0) < 10) {
control.panic(codeRed)
}
```
## See also
[assert](/reference/control/assert), [error codes](/device/error-codes)

View File

@ -8,3 +8,7 @@ control.raiseEvent(control.eventSourceId(EventBusSource.MICROBIT_ID_BUTTON_A), c
**This is an advanced API.** For more information, see the
[@boardname@ runtime messageBus documentation](https://lancaster-university.github.io/microbit-docs/ubit/messageBus/)
## See Also
[radio raise event](/reference/radio/raise-event)

View File

@ -7,8 +7,15 @@ This function is like pressing the reset button on the back of the @boardname@.
```sig
control.reset()
```
## ~hint
### Example
**Simulator**
The **reset** function works only on a real @boardname@ and not in the simulator.
## ~
## Example
This program will count as high as you like when you press button `A`.
When you get tired of counting, press button `B` to reset the
@ -26,12 +33,6 @@ input.onButtonPressed(Button.B, () => {
});
```
#### ~hint
This program works better on a real @boardname@ than in the simulator.
#### ~
### See Also
## See also
[clear screen](/reference/basic/clear-screen), [game over](/reference/game/game-over)

View File

@ -6,7 +6,7 @@ Blocks the current fiber for the given amount of micro-seconds.
control.waitMicros(4)
```
### Example
## Example
This program sends a 10 micro-second HIGH pulse through pin ``P0``.
@ -21,12 +21,12 @@ control.waitMicros(10)
pins.digitalWritePin(DigitalPin.P0, 0)
```
#### ~hint
### ~hint
This function is not supported in the simulator.
#### ~
### ~
### See Also
## See Also
[pause](/reference/basic/pause)