Task 4.4.4 Solution
Fork of Task444Solution by
Diff: main.cpp
- Revision:
- 2:8ec2bcaa0346
- Parent:
- 0:83a9911ab6ec
--- a/main.cpp Thu Jul 13 14:55:28 2017 +0000
+++ b/main.cpp Wed Sep 18 15:21:20 2019 +0000
@@ -11,10 +11,10 @@
#define N 16
//Shared variables
-volatile static unsigned short sample16 = 0;
+volatile static uint16_t sample16 = 0;
-unsigned int sum = 0;
-unsigned int count = 0;
+uint32_t sum = 0;
+uint32_t counter = 0;
//The ticker, used to sample data at a fixed rate
Ticker t;
@@ -37,18 +37,20 @@
sum += sample16;
//Increment the count
- count++;
+ counter = counter + 1;
//Enough to calculate the average?
- if (count == N) {
+ if (counter == N) {
//Divide sum by 16
unsigned short mean = (sum >> 4);
//Display
pc.printf("Mean = %hu\n", mean);
+ wait(0.0014); //Wait for buffer to clear
//Reset sum and count
- count = sum = 0;
+ counter = 0;
+ sum = 0;
}
} //end while(1)
