測定結果をcm表示(10回の平均)

Dependencies:   mbed

Fork of Infra-RedSeonsor by electronics-lab

Files at this revision

API Documentation at this revision

Comitter:
kurikuri
Date:
Wed Apr 04 06:12:54 2018 +0000
Parent:
0:b40d3d1793b1
Commit message:
cm??;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b40d3d1793b1 -r 9d0c57c475ce main.cpp
--- a/main.cpp	Wed Apr 04 02:10:50 2018 +0000
+++ b/main.cpp	Wed Apr 04 06:12:54 2018 +0000
@@ -6,8 +6,12 @@
 
 int main() {
     while(1){
-        distance = ain.read();
-        pc.printf("Distance:%f\n\r",distance);
+        double x = 0;
+        for(int i=0;i<10;i++){
+            distance = 53.444*pow(double(ain.read()),-1.736)/10;
+            x += distance;
+        }
+        pc.printf("Distance:%f\n\r",x/10);
         wait(0.5);
     }
 }