upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Public Member Functions | List of all members

API for the Analog Microphone. More...

Detailed Description

This module defines the Analog Microphone sensor

mic.jpg
short[] buffer = new short[128];
// Attach microphone to analog port A0
ctx.setAverageReading(0);
ctx.setRunningAverage(0);
ctx.setAveragedOver(2);
// Repeatedly, take a sample every 2 microseconds;
// find the average of 128 samples; and
// print a running graph of the averages
while (true) {
int len = sensor.getSampledWindow(2, buffer);
if (len != 0) {
int thresh = sensor.findThreshold(ctx, 30, buffer);
sensor.printGraph(ctx);
if (thresh != 0) {
System.out.println("---Threshold reached--- " + ctx.getRunningAverage() + " "
+ ctx.getAverageReading());
}
}
}

Public Member Functions

synchronized void delete ()
 
 Microphone (int micPin)
 
int getSampledWindow (long freqMS, short[] numberOfSamples)
 
int findThreshold (thresholdContext ctx, long threshold, short[] buffer)
 
void printGraph (thresholdContext ctx)
 

Constructor & Destructor Documentation

Microphone ( int  micPin)

Instantiates a Microphone object

Parameters
micPinPin where the microphone is connected

Member Function Documentation

void printGraph ( thresholdContext  ctx)

Prints a running average of the threshold context

Parameters
ctxThreshold context

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