Reference Language | Libraries | Comparison | Changes
PDM : PDM class
onReceive()
Description
Set the callback function that is called when new PDM data is ready to be read.
Syntax
PDM.onReceive(callback)
Parameters
callback: function that is called when new PDM data is ready to be read
Returns
Nothing
Example
…
// buffer to read samples into, each sample is 16-bits
short sampleBuffer[256];
// number of samples read
volatile int samplesRead;
// …
// configure the data receive callback
PDM.onReceive(onPDMdata);
// initialize PDM with:
// - one channel (mono mode)
// - a 16 kHz sample rate
if (!PDM.begin(1, 16000)) {
Serial.println("Failed to start PDM!");
while (1);
}
// …
void onPDMdata() {
// query the number of bytes available
int bytesAvailable = PDM.available();
// read into the sample buffer
Int bytesRead = PDM.read(sampleBuffer, bytesAvailable);
// 16-bit, 2 bytes per sample
samplesRead = bytesRead / 2;
}
…
See Also
Reference Home
Corrections, suggestions, and new documentation should be posted to the Forum.
The text of the Arduino reference is licensed under a
Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.