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 00037 class HCSR04 { 00038 public: 00039 HCSR04(PinName t, PinName e); 00040 long echo_duration(); 00041 long distance(); 00042 bool timedOut; 00043 00044 private: 00045 DigitalOut trig; 00046 DigitalIn echo; 00047 Timer timer; 00048 Timer timeout_timer; 00049 long duration,distance_cm; 00050 }; 00051 00052 #endif
Generated on Sun Jul 17 2022 07:54:23 by
1.7.2
