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

Dependencies:   mbed

main.cpp

Committer:
tsumagari
Date:
2016-12-02
Revision:
1:29f4aa7418eb
Parent:
0:ee1032401c3e

File content as of revision 1:29f4aa7418eb:

#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*0.017262 + 2.1727);
        wait(0.5);
    }
}