pxt-calliope/docs/reference/pins/on-pulsed.md

32 lines
827 B
Markdown
Raw Normal View History

2016-07-06 01:36:09 +02:00
# On Pulsed
Configure the specified pin for digital input, and then
execute the associated code block whenever the pin
pulses **High** or **Low** (as specified).
```sig
pins.onPulsed(DigitalPin.P0, PulseValue.High, () => { });
```
## Parameters
2016-07-06 01:36:09 +02:00
2016-11-02 01:44:37 +01:00
* ``name``: The @boardname@ hardware pin to configure (``P0`` through ``P20``)
2016-07-19 00:51:28 +02:00
* ``pulse``: Which state will cause the associated block to execute (**High** or **Low**)
2016-07-06 01:36:09 +02:00
## Example
2016-07-06 01:36:09 +02:00
The following example configures pin ``P2`` for digital input,
and then displays the string `LOW` whenever ``P2`` pulses low.
```blocks
pins.onPulsed(DigitalPin.P2, PulseValue.Low, () => {
basic.showString("LOW");
});
```
## 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)