File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ short sampleBuffer[256];
12
12
volatile int samplesRead;
13
13
14
14
bool record = false ;
15
+ bool commandRecv = false ;
15
16
16
17
void setup () {
17
18
Serial.begin (9600 );
@@ -28,7 +29,7 @@ void setup() {
28
29
}
29
30
30
31
Serial.println (" Welcome to the microphone test for the built-in microphone on the Nano 33 BLE Sense\n " );
31
- Serial.println (" Use the on-shield button to start and stop an audio recording" );
32
+ Serial.println (" Use the on-shield button or send the command 'click' to start and stop an audio recording" );
32
33
Serial.println (" Open the Serial Plotter to view the corresponding waveform" );
33
34
}
34
35
@@ -39,15 +40,33 @@ void loop() {
39
40
record = !record;
40
41
}
41
42
42
- if (samplesRead) {
43
+ // see if a command was sent over the serial monitor and record it if so
44
+ String command;
45
+ while (Serial.available ()) {
46
+ char c = Serial.read ();
47
+ if ((c != ' \n ' ) && (c != ' \r ' )) {
48
+ command.concat (c);
49
+ }
50
+ else if (c == ' \r ' ) {
51
+ commandRecv = true ;
52
+ command.toLowerCase ();
53
+ }
54
+ }
55
+
56
+ // parse the command if applicable
57
+ if (commandRecv && command == " click" ) {
58
+ commandRecv = false ;
59
+ record = !record;
60
+ }
43
61
62
+ // display the audio if applicable
63
+ if (samplesRead) {
44
64
// print samples to serial plotter
45
65
if (record) {
46
66
for (int i = 0 ; i < samplesRead; i++) {
47
67
Serial.println (sampleBuffer[i]);
48
68
}
49
69
}
50
-
51
70
// clear read count
52
71
samplesRead = 0 ;
53
72
}
You can’t perform that action at this time.
0 commit comments