Skip to content

Commit 5b3d334

Browse files
Add test to print to serial the mic StreamNormaliser zeroOffset. (#73)
1 parent 2d341e0 commit 5b3d334

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

source/samples/MicrophoneTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdio.h>
12
#include "MicroBit.h"
23
#include "SerialStreamer.h"
34
#include "StreamNormalizer.h"
@@ -69,6 +70,26 @@ mems_mic_test()
6970
uBit.sleep(1000);
7071
}
7172

73+
// WARNING! For this test to run correctly floats for printf/sprintf/snprintf
74+
// have to be enabled by adding this flag to the linker (target.json):
75+
// -u _printf_float
76+
void
77+
mems_mic_zero_offset_test()
78+
{
79+
LevelDetectorSPL* levelSPL = new LevelDetectorSPL(uBit.audio.processor->output, 85.0, 65.0, 16.0, 0, DEVICE_ID_SYSTEM_LEVEL_DETECTOR, false);
80+
uBit.audio.activateMic();
81+
82+
char float_str[20];
83+
volatile auto value = 0;
84+
85+
while (true) {
86+
value = levelSPL->getValue();
87+
snprintf(float_str, 80, "%.4f", uBit.audio.processor->zeroOffset);
88+
uBit.serial.printf("%s\n", float_str);
89+
uBit.sleep(1);
90+
}
91+
}
92+
7293
void
7394
mems_clap_test(int wait_for_clap)
7495
{

source/samples/Tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void display_test2();
2222
void concurrent_display_test();
2323
void fade_test();
2424
void mems_mic_test();
25+
void mems_mic_zero_offset_test();
2526
void speaker_test(int plays);
2627
void speaker_test2(int plays);
2728
void gpio_test();

0 commit comments

Comments
 (0)