Skip to content

Commit be949c6

Browse files
committed
Fix skeetch
1 parent 763ad0e commit be949c6

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

content/hardware/05.nicla/boards/nicla-vision/tutorials/microphone_sensor/microphone_sensor.md

+13-16
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Or find the full edited sketch in our **Arduino_Pro_Tutorials** library.
8787
This example code is in the public domain.
8888
*/
8989
90+
9091
#include <PDM.h>
9192
9293
// default number of output channels
@@ -101,13 +102,14 @@ Or find the full edited sketch in our **Arduino_Pro_Tutorials** library.
101102
// Number of audio samples read
102103
volatile int samplesRead;
103104
104-
// Variables to change the blinking speed of the LED
105-
int speed;
106-
int timeStart = 0;
105+
// Blinking
107106
bool state = false;
107+
int timeStart = 0;
108108
109109
void setup() {
110110
Serial.begin(9600);
111+
pinMode(LEDB, OUTPUT);
112+
111113
while (!Serial);
112114
113115
// Configure the data receive callback
@@ -126,8 +128,6 @@ Or find the full edited sketch in our **Arduino_Pro_Tutorials** library.
126128
while (1);
127129
}
128130
129-
// Set the LED
130-
pinMode(LEDB, OUTPUT);
131131
132132
}
133133
@@ -137,32 +137,29 @@ Or find the full edited sketch in our **Arduino_Pro_Tutorials** library.
137137
138138
// Print samples to the serial monitor or plotter
139139
for (int i = 0; i < samplesRead; i++) {
140-
if(channels == 2) {
140+
if (channels == 2) {
141141
Serial.print("L:");
142142
Serial.print(sampleBuffer[i]);
143143
Serial.print(" R:");
144144
i++;
145145
}
146146
Serial.println(sampleBuffer[i]);
147-
speed = sampleBuffer[i];
148147
}
149148
150149
// Clear the read count
151150
samplesRead = 0;
152-
}
153151
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+
}
159156
}
160157
}
161158
162159
/**
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.
166163
* */
167164
void onPDMdata() {
168165
// Query the number of available bytes

0 commit comments

Comments
 (0)