Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of HCSR04 by
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 class HCSR04 { 00037 public: 00038 HCSR04(PinName t, PinName e, long to); 00039 long echo_duration(); 00040 long distance(); 00041 00042 private: 00043 DigitalOut trig; 00044 DigitalIn echo; 00045 Timer timer; 00046 long duration,distance_cm,time_out; 00047 }; 00048 00049 #endif
Generated on Mon Aug 1 2022 15:37:37 by
1.7.2
