Task 4.4.4 Solution
Fork of Task444Solution by
Revision 2:8ec2bcaa0346, committed 2019-09-18
- Comitter:
- noutram
- Date:
- Wed Sep 18 15:21:20 2019 +0000
- Parent:
- 1:f0954f86b4f2
- Commit message:
- 2019
Changed in this revision
--- 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)
--- a/mbed-os.lib Thu Jul 13 14:55:28 2017 +0000 +++ b/mbed-os.lib Wed Sep 18 15:21:20 2019 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#8828635da469162cf2854b5287561c663fb96e72 +https://github.com/ARMmbed/mbed-os/#1bf6b20df9d3cd5f29f001ffc6f0d0fcbbb96118
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json Wed Sep 18 15:21:20 2019 +0000
@@ -0,0 +1,3 @@
+{
+ "requires": ["bare-metal"]
+}
\ No newline at end of file
