@@ -87,6 +87,7 @@ Or find the full edited sketch in our **Arduino_Pro_Tutorials** library.
87
87
This example code is in the public domain.
88
88
*/
89
89
90
+
90
91
#include <PDM.h>
91
92
92
93
// default number of output channels
@@ -101,13 +102,14 @@ Or find the full edited sketch in our **Arduino_Pro_Tutorials** library.
101
102
// Number of audio samples read
102
103
volatile int samplesRead;
103
104
104
- // Variables to change the blinking speed of the LED
105
- int speed;
106
- int timeStart = 0;
105
+ // Blinking
107
106
bool state = false;
107
+ int timeStart = 0;
108
108
109
109
void setup() {
110
110
Serial.begin(9600);
111
+ pinMode(LEDB, OUTPUT);
112
+
111
113
while (!Serial);
112
114
113
115
// Configure the data receive callback
@@ -126,8 +128,6 @@ Or find the full edited sketch in our **Arduino_Pro_Tutorials** library.
126
128
while (1);
127
129
}
128
130
129
- // Set the LED
130
- pinMode(LEDB, OUTPUT);
131
131
132
132
}
133
133
@@ -137,32 +137,29 @@ Or find the full edited sketch in our **Arduino_Pro_Tutorials** library.
137
137
138
138
// Print samples to the serial monitor or plotter
139
139
for (int i = 0; i < samplesRead; i++) {
140
- if(channels == 2) {
140
+ if (channels == 2) {
141
141
Serial.print("L:");
142
142
Serial.print(sampleBuffer[i]);
143
143
Serial.print(" R:");
144
144
i++;
145
145
}
146
146
Serial.println(sampleBuffer[i]);
147
- speed = sampleBuffer[i];
148
147
}
149
148
150
149
// Clear the read count
151
150
samplesRead = 0;
152
- }
153
151
154
- //Blinking of the LEDB
155
- if(millis() - timeStart > speed){
156
- digitalWrite(LEDB, state);
157
- state = !state;
158
- timeStart = millis();
152
+ if (millis() - timeStart > sampleBuffer[2]) {
153
+ digitalWrite(LEDB, state);
154
+ state = !state;
155
+ }
159
156
}
160
157
}
161
158
162
159
/**
163
- * Callback function to process the data from the PDM microphone.
164
- * NOTE: This callback is executed as part of an ISR.
165
- * Therefore using `Serial` to print messages inside this function isn't supported.
160
+ Callback function to process the data from the PDM microphone.
161
+ NOTE: This callback is executed as part of an ISR.
162
+ Therefore using `Serial` to print messages inside this function isn't supported.
166
163
* */
167
164
void onPDMdata() {
168
165
// Query the number of available bytes
0 commit comments