Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
|
A class to measure the duration of a pulse on a digital pin. More...
#include <PulseIn.h>
Public Member Functions | |
PulseIn (BelaContext *context, unsigned int digitalInput, int direction=1) | |
void | setup (BelaContext *context, unsigned int digitalInput, int direction=1) |
void | check (BelaContext *context) |
int | hasPulsed (BelaContext *context, unsigned int frame) |
void | cleanup () |
A class to measure the duration of a pulse on a digital pin.
This can be used to measure distance in conjunction with an ultrasonic ranging sensor (e.g.: HC-SR04).
|
inline |
Initializes the PulseIn object. Also takes care of setupializing the digital pin as input.
context | the BelaContext |
digitalInput | the digital input where to activate a pulse detector |
direction | the direction of the pulse, can be 1 to detect positive pulses, e.g.:( 0 0 0 0 1 1 0 0 0 0 0) or -1 to detect negative pulses, e.g.: ( 1 1 1 1 0 0 1 1 1 1) |
void PulseIn::setup | ( | BelaContext * | context, |
unsigned int | digitalInput, | ||
int | direction = 1 |
||
) |
Initializes the PulseIn object. Also takes care of initializing the digital pin as input.
If the object has been created with the default constructor, the user will need to call setup() before calling check() or hasPulsed().
context | the BelaContext |
digitalInput | the digital input where to activate a pulse detector |
direction | the direction of the pulse, can be 1 to detect positive pulses, e.g.:( 0 0 0 0 1 1 0 0 0 0 0) or -1 to detect negative pulses, e.g.: ( 1 1 1 1 0 0 1 1 1 1) |
void PulseIn::check | ( | BelaContext * | context | ) |
Detects pulses.
The user does not need to call this method as long as they call hasPulsed() at least once per context. The rationale why we check() for pulses in a different method than hasPulsed() is because user might not query for hasPulsed() every sample, so we are safe so long as they call hasPulsed() or check() at least once per buffer. Also, results are cached (i.e.: we do not check() for pulses twice for the same context. context->audioFramesElapsed is used as an identifier.
|
inline |
Looks for the end of a pulse.
context | the current BelaContext |
frame | the frame at which to check if a pulse was detected. |