This commit is contained in:
Juri
2020-08-19 22:03:58 +02:00
parent 4ef7b9318f
commit 3152215415
291 changed files with 9511 additions and 2966 deletions

View File

@ -29,7 +29,7 @@ control.inBackground(() => {
basic.pause(100)
}
})
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
input.onButtonPressed(Button.A, () => {
num++;
})
```
@ -42,7 +42,7 @@ let num = 0
basic.forever(() => {
basic.showNumber(num)
})
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
input.onButtonPressed(Button.A, () => {
num++;
})
```

View File

@ -0,0 +1,25 @@
# millis
Get the number of milliseconds of time passed since the board was turned on.
```sig
control.millis()
```
## Returns
* the [number](/types/number) of milliseconds of time since the board was turned on.
## Example #example
Find how many days, hours, minutes, and seconds the @boardname@ has been running.
```blocks
let msecs = control.millis()
let seconds = msecs / 1000
let mins = seconds / 60
let hours = mins / 60
let days = hours / 24
```
## #seealso

View File

@ -24,11 +24,11 @@ When you get tired of counting, press button `B` to reset the
```blocks
let item = 0;
basic.showNumber(item);
input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
input.onButtonPressed(Button.A, () => {
item = item + 1;
basic.showNumber(item);
});
input.onButtonEvent(Button.B, ButtonEvent.Click, () => {
input.onButtonPressed(Button.B, () => {
control.reset();
});
```

View File

@ -0,0 +1,67 @@
# wait For Event
Stop running the current code and wait for an event.
```sig
control.waitForEvent(0, 0)
```
You might want your code to stop for a while until some event you're expecting happens.
If you want your code to pause until a known event happens, use a ``||control:wait for event||`` block.
A known event is something you identify that happens on the board or in your program.
An event has both a source and a cause. The source is where the event comes from, like a sensor or
some condition in your program. The cause is what made the event happen at the source.
You assign numbers for your event sources and causes. These numbers are used by [``||control:raise event||``](/reference/control/raise-event) to announce to your program that an event just happened.
As an example, you could make a timer that always causes an event every 100 milliseconds. The source
number for the timer is `6` and the cause value is `1`. The program could wait for one of the time
events like this:
```blocks
const myTimer = 6;
const timerTimeout = 1;
control.runInParallel(function() {
while (true) {
control.waitMicros(100000)
control.raiseEvent(myTimer, timerTimeout)
}
})
control.waitForEvent(myTimer, timerTimeout)
```
## Parameters
* **id**: the identification [number](/types/number) (the source) of this event, such as: `10`.
* **value**: a [number](/types/number) tells what the cause of the event is, like: `4`.
## Example #example
Make a timeout timer to signal every 2 seconds. Wait two times and write to the
console each time.
```blocks
const myTimer = 6;
const timerTimeout = 1;
control.runInParallel(function() {
while (true) {
pause(2000)
control.raiseEvent(myTimer, timerTimeout)
}
})
control.waitForEvent(myTimer, timerTimeout)
console.log("Timer timeout")
control.waitForEvent(myTimer, timerTimeout)
console.log("Timer timeout")
```
**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 #seealso
[raise event](/reference/control/raise-event), [on event](/reference/control/on-event)