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];
1212volatile int samplesRead;
1313
1414bool record = false ;
15+ bool commandRecv = false ;
1516
1617void setup () {
1718 Serial.begin (9600 );
@@ -28,7 +29,7 @@ void setup() {
2829 }
2930
3031 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" );
3233 Serial.println (" Open the Serial Plotter to view the corresponding waveform" );
3334}
3435
@@ -39,15 +40,33 @@ void loop() {
3940 record = !record;
4041 }
4142
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+ }
4361
62+ // display the audio if applicable
63+ if (samplesRead) {
4464 // print samples to serial plotter
4565 if (record) {
4666 for (int i = 0 ; i < samplesRead; i++) {
4767 Serial.println (sampleBuffer[i]);
4868 }
4969 }
50-
5170 // clear read count
5271 samplesRead = 0 ;
5372 }
You can’t perform that action at this time.
0 commit comments