Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Public Member Functions | List of all members
PulseIn Class Reference

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 ()
 

Detailed Description

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).

Examples:
Sensors/ultrasonic-distance-sensor/render.cpp.

Constructor & Destructor Documentation

PulseIn::PulseIn ( BelaContext context,
unsigned int  digitalInput,
int  direction = 1 
)
inline

Initializes the PulseIn object. Also takes care of setupializing the digital pin as input.

Parameters
contextthe BelaContext
digitalInputthe digital input where to activate a pulse detector
directionthe 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)

Member Function Documentation

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().

Parameters
contextthe BelaContext
digitalInputthe digital input where to activate a pulse detector
directionthe 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)
Examples:
Sensors/ultrasonic-distance-sensor/render.cpp.
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.

int PulseIn::hasPulsed ( BelaContext context,
unsigned int  frame 
)
inline

Looks for the end of a pulse.

Parameters
contextthe current BelaContext
framethe frame at which to check if a pulse was detected.
Returns
the length of the pulse if a pulse ending was detected at sample n, zero otherwise.
Examples:
Sensors/ultrasonic-distance-sensor/render.cpp.

The documentation for this class was generated from the following files: