added wait-micros function

This commit is contained in:
Peli de Halleux 2016-08-16 17:04:21 -07:00
parent 851687dba8
commit 9159c297a5
5 changed files with 58 additions and 3 deletions

View File

@ -7,8 +7,9 @@ control.inBackground(() => {
});
control.reset();
control.waitMicros(4);
```
### See Also
[inBackground](/reference/control/in-background), [reset](/reference/control/reset)
[inBackground](/reference/control/in-background), [reset](/reference/control/reset), [wait-micros](/reference/control/wait-micros)

View File

@ -0,0 +1,32 @@
# WaitMicros
Blocks the current fiber for the given amount of micro-seconds.
```sig
control.waitMicros(4)
```
### Example
This program sends a 10 micro-second HIGH pulse through pin ``P0``.
```blocks
// ensure pin is low to send a clean pulse
pins.digitalWritePin(DigitalPin.P0, 0)
control.waitMicros(2)
// set pin to 1 and wait 10 micros
pins.digitalWritePin(DigitalPin.P0, 1)
control.waitMicros(10)
// finish pulse
pins.digitalWritePin(DigitalPin.P0, 0)
```
#### ~hint
This function is not supported in the simulator.
#### ~
### See Also
[pause](/reference/basic/pause)

View File

@ -129,12 +129,22 @@ namespace control {
/**
* Resets the BBC micro:bit.
*/
//% weight=30 async help=control/reset
//% weight=30 async help=control/reset blockGap=8
//% blockId="control_reset" block="reset"
void reset() {
microbit_reset();
}
/**
* Blocks the current fiber for the given microseconds
* @param micros number of micro-seconds to wait. eg: 4
*/
//% help=control/wait-micros weight=29
//% blockId="control_wait_us" block="wait (µs)%micros"
void waitMicros(int micros) {
wait_us(micros);
}
/**
* Raises an event in the event bus.
* @param src ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A.

View File

@ -333,10 +333,18 @@ declare namespace control {
/**
* Resets the BBC micro:bit.
*/
//% weight=30 async help=control/reset
//% weight=30 async help=control/reset blockGap=8
//% blockId="control_reset" block="reset" shim=control::reset
function reset(): void;
/**
* Blocks the current fiber for the given microseconds
* @param micros number of micro-seconds to wait. eg: 4
*/
//% help=control/wait-micros weight=29
//% blockId="control_wait_us" block="wait (µs)%micros" shim=control::waitMicros
function waitMicros(micros: number): void;
/**
* Raises an event in the event bus.
* @param src ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A.

View File

@ -227,6 +227,10 @@ namespace pxsim.control {
U.userError("reset not implemented in simulator yet")
}
export function waitMicros(micros: number) {
// TODO
}
export function deviceName(): string {
let b = board();
return b && b.id