Komut
onReceive()
Açıklama
Yeni PDM verileri okunmaya hazır olduğunda çağrılan geri arama işlevini ayarlayın.
Sözdizimi
PDM.onReceive (geri)
Parametreler
callback : yeni PDM verileri okunmaya hazır olduğunda çağrılan işlev
İadeler
Hiçbir şey değil
Misal
…
// 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;
}
…
// 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;
}
…