2019-12-02 05:58:26 +01:00
|
|
|
# on Pulsed
|
2016-07-06 01:36:09 +02:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
Set a pin to use as a digital input and then run some code when the pin pulses either ``high`` or ``low``.
|
2016-07-06 01:36:09 +02:00
|
|
|
|
|
|
|
```sig
|
|
|
|
pins.onPulsed(DigitalPin.P0, PulseValue.High, () => { });
|
|
|
|
```
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
### ~ hint
|
2016-07-06 01:36:09 +02:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
**Simulator**: This function needs real hardware to work with. It's not supported in the simulator.
|
2016-07-06 01:36:09 +02:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
### ~
|
2016-07-06 01:36:09 +02:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## Parameters
|
|
|
|
|
|
|
|
* **name**: the @boardname@ hardware pin to set for digital input (``P0`` through ``P20``).
|
|
|
|
* **pulse**: the state that will cause the code inside the block to run, either ``high`` or ``low``.
|
|
|
|
* **body**: the code to run when the pin in **name** is pulsed to the state set in **pulse**.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
Configure pin ``P2`` for digital input. Display the string `"LOW"` whenever ``P2`` pulses ``low``.
|
2016-07-06 01:36:09 +02:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
pins.onPulsed(DigitalPin.P2, PulseValue.Low, () => {
|
|
|
|
basic.showString("LOW");
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## See also
|
2016-07-06 01:36:09 +02:00
|
|
|
|
|
|
|
[servo set pulse](/reference/pins/servo-set-pulse),
|
|
|
|
[pulse duration](/reference/pins/pulse-duration),
|
|
|
|
[digital read pin](/reference/pins/digital-read-pin)
|