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: mbed
Diff: main.cpp
- Revision:
- 3:9902261b1156
- Parent:
- 2:22d86efbbada
- Child:
- 4:ff05e1fe33ce
- Child:
- 5:0382ed1bf13d
--- a/main.cpp Sat Mar 11 12:44:14 2017 +0000
+++ b/main.cpp Sat Mar 11 13:08:06 2017 +0000
@@ -37,7 +37,7 @@
void turn(float s); //turn car -1 left 0 centre 1 right
void drive(float v); //drive -1 reverse 1 forward
void stop(void);
-int measurement_mean(int *Array);
+int measurement_mean(int chan);
int main() {
@@ -74,11 +74,11 @@
US4_mean[i] = US1_mean[i-1];
US5_mean[i] = US1_mean[i-1];
}
- mean_measured1[0] = measurement_mean(&US1_mean);
- mean_measured2[0] = measurement_mean(&US2_mean);
- mean_measured3[0] = measurement_mean(&US3_mean);
- mean_measured4[0] = measurement_mean(&US4_mean);
- mean_measured5[0] = measurement_mean(&US5_mean);
+ mean_measured1[0] = measurement_mean(1); //calc mean 1
+ mean_measured2[0] = measurement_mean(2); //calc mean 2
+ mean_measured3[0] = measurement_mean(3); //calc mean 3
+ mean_measured4[0] = measurement_mean(4); //calc mean 4
+ mean_measured5[0] = measurement_mean(5); //calc mean 5
if(iMean == 1){
mean_measured1[1] = mean_measured1[0];
@@ -182,12 +182,41 @@
return;
}
-int measurement_mean(int *Array){
+int measurement_mean(int chan){
int value=0;
int sum = 0;
- for(int i=0;i<=MAX;i++){
- sum +=Array[i];
+ switch (chan){
+ case 1:
+ for(int i=0;i<=MAX;i++){
+ sum += US1_mean[i]; //sum all elements of US1 window
+ }
+ value = sum/MAX; //calculate mean for US1
+ return (int)value; //return using type casting
+ case 2:
+ for(int i=0;i<=MAX;i++){
+ sum +=US2_mean[i]; //sum all elements of US2 window
+ }
+ value = sum/MAX; //calculate mean for US2
+ return (int)value; //return using type casting
+ case 3:
+ for(int i=0;i<=MAX;i++){
+ sum +=US3_mean[i]; //sum all elements of US3 window
+ }
+ value = sum/MAX; //calculate mean for US3
+ return (int)value; //return using type casting
+ case 4:
+ for(int i=0;i<=MAX;i++){
+ sum +=US4_mean[i]; //sum all elements of US4 window
+ }
+ value = sum/MAX; //calculate mean for US4
+ return (int)value; //return using type casting
+ case 5:
+ for(int i=0;i<=MAX;i++){
+ sum +=US5_mean[i]; //sum all elements of US5 window
+ }
+ value = sum/MAX; //calculate mean for US5
+ return (int)value; //return using type casting
}
- value = sum/MAX;
- return (int)value;
+
+ return 0;
}