pxt-calliope/docs/reference/pins/pulse-duration.md
Galen Nickel 079cd67c38 Update 'pins' ref pages ()
* Update 'pins' ref pages

* Some jsdoc touchups
2019-01-03 16:02:19 -08:00

908 B

pulse Duration

Get the duration of the last pulse in microseconds.

pins.pulseDuration();

A pin pulse is detected in the onPulsed event. You use pulseDuration inside that event to get the duration of the pulse that triggered the event.

~ hint

Simulator: This function needs real hardware to work with. It's not supported in the simulator.

~

Returns

  • a number that is the duration of the last pulse, measured in microseconds.

Example

Wait for pin P0 to be pulsed high. Display the duration of the pulse in microseconds on the LED screen.

pins.onPulsed(DigitalPin.P0, PulseValue.High, () => {
    basic.showNumber(pins.pulseDuration());
});

See also

servo set pulse, on pulsed, digital read pin