XL-MaxSonar MB1260 高度計のテストプログラムです。

Dependencies:   mbed

main.cpp

Committer:
tsumagari
Date:
2016-11-30
Revision:
0:ee1032401c3e
Child:
1:29f4aa7418eb

File content as of revision 0:ee1032401c3e:

#include "mbed.h"

Serial pc(USBTX,USBRX);
Timer sonerTimer;
InterruptIn sonerPin(p22);
double sonerDistTime=0;

void sonerInterruptStart(){
    sonerTimer.start();
}
void sonerInterruptStop(){
    sonerTimer.stop();
    sonerDistTime = sonerTimer.read_us();
    sonerTimer.reset();
}

int main() {
    sonerPin.rise(&sonerInterruptStart);
    sonerPin.fall(&sonerInterruptStop);
    while(1) {
        pc.printf("DistTime: %f\n\r",sonerDistTime);
        pc.printf("CalculatedDist: %f\n\r",sonerDistTime/58.0);
        wait(0.5);
    }
}