Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8c81e31

Browse files
committedMar 1, 2021
PDMSerialPlotter stereo version
1 parent 14e0f40 commit 8c81e31

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed
 

‎libraries/PDM/examples/PDMSerialPlotter/PDMSerialPlotter.ino

100644100755
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55
66
Circuit:
77
- Arduino Nano 33 BLE board
8+
- Arduino Portenta H7 board
89
910
This example code is in the public domain.
1011
*/
1112

1213
#include <PDM.h>
1314

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+
1421
// buffer to read samples into, each sample is 16-bits
15-
short sampleBuffer[256];
22+
short sampleBuffer[512];
1623

1724
// number of samples read
1825
volatile int samplesRead;
@@ -30,7 +37,7 @@ void setup() {
3037
// initialize PDM with:
3138
// - one channel (mono mode)
3239
// - a 16 kHz sample rate
33-
if (!PDM.begin(1, 16000)) {
40+
if (!PDM.begin(channels, frequency)) {
3441
Serial.println("Failed to start PDM!");
3542
while (1);
3643
}
@@ -42,6 +49,12 @@ void loop() {
4249

4350
// print samples to the serial monitor or plotter
4451
for (int i = 0; i < samplesRead; i++) {
52+
if(channels == 2) {
53+
Serial.print("L:");
54+
Serial.print(sampleBuffer[i]);
55+
Serial.print(" R:");
56+
i++;
57+
}
4558
Serial.println(sampleBuffer[i]);
4659
}
4760

0 commit comments

Comments
 (0)
Please sign in to comment.