STM32 core 3.0.1-dev
Arduino core for STM32 based boards: API reference
← STM32duino documentation
Loading...
Searching...
No Matches
wiring_pulse.cpp File Reference

Pulse width measurement: pulseIn() and pulseInLong(). More...

#include "Arduino.h"

Functions

unsigned long pulseIn (pin_size_t pin, uint8_t state, unsigned long timeout)
 Measures the length (in microseconds) of a pulse on the pin.
 
unsigned long pulseInLong (pin_size_t pin, uint8_t state, unsigned long timeout)
 Measures the length (in microseconds) of a pulse on the pin.
 

Detailed Description

Pulse width measurement: pulseIn() and pulseInLong().

Function Documentation

◆ pulseIn()

unsigned long pulseIn ( pin_size_t  pin,
uint8_t  state,
unsigned long  timeout 
)

Measures the length (in microseconds) of a pulse on the pin.

Works on pulses from 2-3 microseconds to 3 minutes in length, but must be called at least a few dozen microseconds before the start of the pulse.

Note
This function relies on micros() so cannot be used in noInterrupt() context.
Parameters
pinPin number, Dx or x.
stateHIGH or LOW, the type of pulse to measure.
timeoutMaximum time to wait for the whole measure (end of any previous pulse, start and end of the pulse), in microseconds. Defaults to 1 second when omitted in C++.
Returns
Length of the pulse in microseconds, or 0 if the pulse was not completed before the timeout.

◆ pulseInLong()

unsigned long pulseInLong ( pin_size_t  pin,
uint8_t  state,
unsigned long  timeout 
)

Measures the length (in microseconds) of a pulse on the pin.

Same as pulseIn(); provided for compatibility with the AVR core.

Note
This function relies on micros() so cannot be used in noInterrupt() context.
Parameters
pinPin number, Dx or x.
stateHIGH or LOW, the type of pulse to measure.
timeoutMaximum time to wait for the whole measure (end of any previous pulse, start and end of the pulse), in microseconds. Defaults to 1 second when omitted in C++.
Returns
Length of the pulse in microseconds, or 0 if the pulse was not completed before the timeout.