Added timeout functionality
Fork of HCSR04 by
hcsr04.h
- Committer:
- EmbeddedSam
- Date:
- 2016-10-24
- Revision:
- 1:e01896ab28d7
- Parent:
- 0:86b2086be101
File content as of revision 1:e01896ab28d7:
/* File: HCSR04.h
* Author: Antonio Buonanno
*Board: STM NUCLEO F401RE,
*Hardware: Ultrasonic Range HC-SR04,
*
*This work derived from Arduino library,
*
* Desc: driver for HCSR04 Ultrasonic Range Finder. The returned range
* is in units of meters.
*
*
*
*/
/* EXAMPLE
#include "mbed.h"
#include "hcsr04.h"
//D12 TRIGGER D11 ECHO
HCSR04 sensor(D12, D11);
int main() {
while(1) {
long distance = sensor.distance();
printf("distanza %d \n",distance);
wait(1.0); // 1 sec
}
}
*/
#ifndef hcsr04_H
#define hcsr04_H
#include "mbed.h"
class HCSR04 {
public:
HCSR04(PinName t, PinName e);
long echo_duration();
long distance();
bool timedOut;
private:
DigitalOut trig;
DigitalIn echo;
Timer timer;
Timer timeout_timer;
long duration,distance_cm;
};
#endif
