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

Dependencies:   mbed

Fork of Infra-RedSeonsor by electronics-lab

Committer:
kurikuri
Date:
Wed Apr 04 06:12:54 2018 +0000
Revision:
1:9d0c57c475ce
Parent:
0:b40d3d1793b1
cm??;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ponpoko1939 0:b40d3d1793b1 1 #include "mbed.h"
ponpoko1939 0:b40d3d1793b1 2
ponpoko1939 0:b40d3d1793b1 3 Serial pc(USBTX,USBRX);
ponpoko1939 0:b40d3d1793b1 4 AnalogIn ain(p20);
ponpoko1939 0:b40d3d1793b1 5 double distance;
ponpoko1939 0:b40d3d1793b1 6
ponpoko1939 0:b40d3d1793b1 7 int main() {
ponpoko1939 0:b40d3d1793b1 8 while(1){
kurikuri 1:9d0c57c475ce 9 double x = 0;
kurikuri 1:9d0c57c475ce 10 for(int i=0;i<10;i++){
kurikuri 1:9d0c57c475ce 11 distance = 53.444*pow(double(ain.read()),-1.736)/10;
kurikuri 1:9d0c57c475ce 12 x += distance;
kurikuri 1:9d0c57c475ce 13 }
kurikuri 1:9d0c57c475ce 14 pc.printf("Distance:%f\n\r",x/10);
ponpoko1939 0:b40d3d1793b1 15 wait(0.5);
ponpoko1939 0:b40d3d1793b1 16 }
ponpoko1939 0:b40d3d1793b1 17 }