upm  0.1.8
Sensor/Actuator repository for libmraa (v0.4.5)
 All Data Structures Files Functions Variables Macros Pages
Public Member Functions
Microphone Class Reference

C++ API for Microphone. More...

Detailed Description

This file defines the Microphone Analog sensor

int
main(int argc, char **argv)
{
sensor = new upm::Microphone(0);
signal(SIGINT, sig_handler);
ctx.averageReading = 0;
ctx.runningAverage = 0;
ctx.averagedOver = 2;
while (!is_running) {
int len = sensor->getSampledWindow (2, 128, buffer);
if (len) {
int thresh = sensor->findThreshold (&ctx, 30, buffer, len);
sensor->printGraph(&ctx);
if (thresh) {
// do something ....
}
}
}
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
}

Public Member Functions

 Microphone (int micPin)
 
 ~Microphone ()
 
int getSampledWindow (unsigned int freqMS, unsigned int numberOfSamples, uint16_t *buffer)
 
int findThreshold (thresholdContext *ctx, unsigned int threshold, uint16_t *buffer, unsigned int len)
 
void printGraph (thresholdContext *ctx)
 

Constructor & Destructor Documentation

Microphone ( int  micPin)

Instanciates a Microphone object

Parameters
micPinpin where microphone is connected
~Microphone ( )

MAX31723 object destructor

Member Function Documentation

int getSampledWindow ( unsigned int  freqMS,
unsigned int  numberOfSamples,
uint16_t *  buffer 
)

Get samples from microphone according to provided window and number of samples

Parameters
freqMStime between each sample (in microseconds)
numberOfSamplesnumber of sample to sample for this window
bufferbufer with sampled data
int findThreshold ( thresholdContext ctx,
unsigned int  threshold,
uint16_t *  buffer,
unsigned int  len 
)

Given sampled buffer this method will return TRUE/FALSE if threshold was reached

Parameters
ctxthreshold context
thresholdsample threshold
bufferbuffer with samples
lenbufer len
void printGraph ( thresholdContext ctx)

Print running average of threshold context

Parameters
ctxthreshold context

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