Skip to content

Commit 2cd3540

Browse files
authored
Merge pull request #149 from pennam/serial_plotter
PDMSerialPlotter stereo version
2 parents f1b6c05 + 3cb4787 commit 2cd3540

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

libraries/PDM/examples/PDMSerialPlotter/PDMSerialPlotter.ino

100644100755
+14-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@
1212

1313
#include <PDM.h>
1414

15+
// default number of output channels
16+
static const char channels = 1;
17+
18+
// default PCM output frequency
19+
static const int frequency = 16000;
20+
1521
// Buffer to read samples into, each sample is 16-bits
16-
short sampleBuffer[256];
22+
short sampleBuffer[512];
1723

1824
// Number of audio samples read
1925
volatile int samplesRead;
@@ -33,7 +39,7 @@ void setup() {
3339
// - one channel (mono mode)
3440
// - a 16 kHz sample rate for the Arduino Nano 33 BLE Sense
3541
// - a 32 kHz or 64 kHz sample rate for the Arduino Portenta Vision Shield
36-
if (!PDM.begin(1, 16000)) {
42+
if (!PDM.begin(channels, frequency)) {
3743
Serial.println("Failed to start PDM!");
3844
while (1);
3945
}
@@ -45,6 +51,12 @@ void loop() {
4551

4652
// Print samples to the serial monitor or plotter
4753
for (int i = 0; i < samplesRead; i++) {
54+
if(channels == 2) {
55+
Serial.print("L:");
56+
Serial.print(sampleBuffer[i]);
57+
Serial.print(" R:");
58+
i++;
59+
}
4860
Serial.println(sampleBuffer[i]);
4961
}
5062

0 commit comments

Comments
 (0)