Reference   Language | Libraries | Comparison | Changes

PDM : PDM class

read()

Description

Read data from the PDM into the specified buffer.

Syntax

PDM.read(buffer, size)

Parameters

buffer: array to store the PDM data into
size: number of bytes to read

Returns

The number of bytes read

Example


// buffer to read samples into, each sample is 16-bits
short sampleBuffer[256];

// number of samples read
volatile int samplesRead;

// …

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