PulseIn Class Reference

Public Member Functions

 PulseIn (BelaContext *context, unsigned int digitalInput, int direction=1)
 
void init (BelaContext *context, unsigned int digitalInput, int direction=1)
 
void check (BelaContext *context)
 
int hasPulsed (BelaContext *context, int frame)
 

Member Function Documentation

void PulseIn::init ( 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 init() before calling check() or hasPulsed().

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

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