1 sensor using RTOS Timer, another 2 over RTOS Semaphore
Dependents: Autonomous_quadcopter
Fork of HCSR04 by
hcsr04.h
- Committer:
- edy05
- Date:
- 2018-01-20
- Revision:
- 3:81512ca9a13c
- Parent:
- 1:53657de3246f
- Child:
- 7:dcf0aa89bcd7
File content as of revision 3:81512ca9a13c:
/* 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" #include "rtos.h" class HCSR04 { public: HCSR04(PinName t, PinName e); uint16_t getDistance(); uint16_t getDistan(); private: static void threadWorker(void const *p); DigitalOut trig; DigitalIn echo; Timer timer; Thread *thread; RtosTimer *threadUpdateTimer; uint16_t distance_cm; uint32_t distan; }; #endif