2019-12-02 05:58:26 +01:00
|
|
|
# set Events
|
2017-01-30 20:19:54 +01:00
|
|
|
|
|
|
|
Configure the type of events emitted by a given pin.
|
|
|
|
|
|
|
|
```sig
|
|
|
|
pins.setEvents(DigitalPin.P0, PinEventType.Edge);
|
|
|
|
```
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
### ~ hint
|
|
|
|
|
|
|
|
**Simulator**: This function needs real hardware to work with. It's not supported in the simulator.
|
|
|
|
|
|
|
|
### ~
|
|
|
|
|
|
|
|
## Parameters
|
2017-01-30 20:19:54 +01:00
|
|
|
|
|
|
|
* ``name``: The @boardname@ hardware pin to configure (``P0`` through ``P20``)
|
|
|
|
* ``type``: The type of events this pin should emit
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## Example
|
2017-01-30 20:19:54 +01:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
The following example configures pin ``P0`` and then subscribes to the rise and fall events.
|
2017-01-30 20:19:54 +01:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
control.onEvent(control.eventSourceId(EventBusSource.MICROBIT_ID_IO_P0), control.eventValueId(EventBusValue.MICROBIT_PIN_EVT_RISE), () => {
|
|
|
|
basic.showString("Rise")
|
|
|
|
})
|
|
|
|
control.onEvent(control.eventSourceId(EventBusSource.MICROBIT_ID_IO_P0), control.eventValueId(EventBusValue.MICROBIT_PIN_EVT_FALL), () => {
|
|
|
|
basic.showString("Fall")
|
|
|
|
})
|
|
|
|
pins.setEvents(DigitalPin.P0, PinEventType.Edge)
|
|
|
|
```
|
|
|
|
|
|
|
|
**This is an advanced API.** For more information, see the
|
|
|
|
[@boardname@ runtime messageBus documentation](https://lancaster-university.github.io/microbit-docs/ubit/messageBus/)
|