Create this program

Dependencies:   mbed HCSR04 HMC6352 PID TextLCD

ultrasonic.h

Committer:
KoiShin_Sakana
Date:
2015-08-04
Revision:
1:d0cada9a5381
Child:
2:a8bbf677e774

File content as of revision 1:d0cada9a5381:

#ifndef ULTRASONIC_H
#define ULTRASONIC_H

#include "mbed.h"
#include "hcsr04.h"

class Ultrasonic {
private:
    HCSR04* hcsr04;

public:
    int dist;
    Ultrasonic(PinName trig, PinName echo);
    void measureDist(void);
};

Ultrasonic::Ultrasonic(PinName trig, PinName echo) {
    hcsr04 = new HCSR04(trig, echo);
}

void Ultrasonic::measureDist(void) {
    wait(0.1);
    this->dist = hcsr04->distance();
}

#endif

/*
 * example program

#include "mbed.h"
#include "ultrasonic.h"

int main(void) {
    Ultrasonic ultrasonic(D12, D13);
    while (1) {
        ultrasonic.measureDist();
        pc.printf("%d\r\n", ultrasonic.dist);
    }
}
 */