Library for Ultrasonic Range,

Dependents:   burobo_reciverV2 Nucleo_Ultrasonic-HCSR4 Test_UltraSonic Ultrasonic2 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hcsr04.h Source File

hcsr04.h

00001 /* File: HCSR04.h
00002  * Author: Antonio Buonanno  
00003  *Board: STM NUCLEO F401RE, 
00004  *Hardware: Ultrasonic Range HC-SR04,  
00005  * 
00006  *This work derived from Arduino library, 
00007  *
00008  * Desc: driver for HCSR04 Ultrasonic Range Finder.  The returned range
00009  *       is in units of meters.
00010  *  
00011  *       
00012  *
00013 */
00014 
00015 /* EXAMPLE
00016 #include "mbed.h"
00017 #include "hcsr04.h"
00018 
00019 //D12 TRIGGER D11 ECHO
00020    HCSR04 sensor(D12, D11); 
00021 int main() {
00022     while(1) {
00023         
00024      long distance = sensor.distance();   
00025       printf("distanza  %d  \n",distance);
00026       wait(1.0); // 1 sec  
00027         
00028     }
00029 }
00030 */
00031 #ifndef hcsr04_H
00032 #define hcsr04_H
00033 #include "mbed.h"
00034 
00035 
00036  
00037 class HCSR04 {
00038   public:
00039     HCSR04(PinName t, PinName e);
00040     long echo_duration();
00041     long distance();
00042  
00043     private:
00044         DigitalOut trig;
00045         DigitalIn echo;
00046         Timer timer;
00047         long duration,distance_cm;
00048 };
00049  
00050 #endif