Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SmartSwitch TMRh20 mbed
Diff: main.cpp
- Revision:
- 1:2b938172cef5
- Parent:
- 0:7f49ac69d623
- Child:
- 2:5d075b76930a
--- a/main.cpp Thu Mar 17 11:15:02 2016 +0000
+++ b/main.cpp Fri Mar 18 21:34:01 2016 +0000
@@ -11,7 +11,7 @@
Serial pc(USBTX, USBRX);
#define SAMPLE_SIZE 240
-#define PRESAMPLE_SIZE 10
+#define PRESAMPLE_SIZE 60
// Buffers to store the samples of the 4 channels
uint8_t buffer0[SAMPLE_SIZE];
uint8_t buffer1[SAMPLE_SIZE];
@@ -100,17 +100,18 @@
while(1) {
readMics();
- pc.puts(".");
+ //pc.puts(".");
if (!action) {
// Not in action, just listening
if (checkThreshold()) {
- pc.puts("\nThreshold reached!\n");
+ //pc.puts("\nThreshold reached!\n");
action = true;
if (sample_size > PRESAMPLE_SIZE) {
sample_size = PRESAMPLE_SIZE;
}
sample_start = sample_pointer - sample_size;
+ if (sample_start < 0) sample_start += SAMPLE_SIZE;
}
sample_pointer++;
if (sample_pointer > SAMPLE_SIZE) sample_pointer = 0;
@@ -123,11 +124,11 @@
if (sample_size == SAMPLE_SIZE) {
// Stop collecting, send samples
action = false;
- printf("\nSending samples.\n");
- sendSamples(0, buffer0, SAMPLE_SIZE, sample_pointer);
- sendSamples(1, buffer1, SAMPLE_SIZE, sample_pointer);
- sendSamples(2, buffer2, SAMPLE_SIZE, sample_pointer);
- sendSamples(3, buffer3, SAMPLE_SIZE, sample_pointer);
+ sendSamples(0, buffer0, SAMPLE_SIZE, sample_start);
+ sendSamples(1, buffer1, SAMPLE_SIZE, sample_start);
+ sendSamples(2, buffer2, SAMPLE_SIZE, sample_start);
+ sendSamples(3, buffer3, SAMPLE_SIZE, sample_start);
+ printf("\nSamples were sent.\n");
sample_size = 0;
sample_pointer = 0;
}