ultimaact
Dependencies: mbed Adafruit_GFX DS1820
hcsr04.h@0:8a1a447db446, 2021-12-09 (annotated)
- Committer:
- javiervicente
- Date:
- Thu Dec 09 17:59:02 2021 +0000
- Revision:
- 0:8a1a447db446
cambio;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
javiervicente | 0:8a1a447db446 | 1 | /* Copyright (c) 2013 Prabhu Desai |
javiervicente | 0:8a1a447db446 | 2 | * pdtechworld@gmail.com |
javiervicente | 0:8a1a447db446 | 3 | * |
javiervicente | 0:8a1a447db446 | 4 | * |
javiervicente | 0:8a1a447db446 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
javiervicente | 0:8a1a447db446 | 6 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
javiervicente | 0:8a1a447db446 | 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
javiervicente | 0:8a1a447db446 | 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
javiervicente | 0:8a1a447db446 | 9 | * furnished to do so, subject to the following conditions: |
javiervicente | 0:8a1a447db446 | 10 | * |
javiervicente | 0:8a1a447db446 | 11 | * The above copyright notice and this permission notice shall be included in all copies or |
javiervicente | 0:8a1a447db446 | 12 | * substantial portions of the Software. |
javiervicente | 0:8a1a447db446 | 13 | * |
javiervicente | 0:8a1a447db446 | 14 | * For more details on the sensor : |
javiervicente | 0:8a1a447db446 | 15 | * http://www.elecfreaks.com/store/hcsr04-ultrasonic-sensor-distance-measuring-module-p-91.html?zenid=pgm8pgnvaodbe36dibq5s1soi3 |
javiervicente | 0:8a1a447db446 | 16 | * |
javiervicente | 0:8a1a447db446 | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
javiervicente | 0:8a1a447db446 | 18 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
javiervicente | 0:8a1a447db446 | 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
javiervicente | 0:8a1a447db446 | 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
javiervicente | 0:8a1a447db446 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
javiervicente | 0:8a1a447db446 | 22 | */ |
javiervicente | 0:8a1a447db446 | 23 | |
javiervicente | 0:8a1a447db446 | 24 | #ifndef MBED_HCSR04_H |
javiervicente | 0:8a1a447db446 | 25 | #define MBED_HCSR04_H |
javiervicente | 0:8a1a447db446 | 26 | |
javiervicente | 0:8a1a447db446 | 27 | #include "mbed.h" |
javiervicente | 0:8a1a447db446 | 28 | |
javiervicente | 0:8a1a447db446 | 29 | /** HCSR04 Class(es) |
javiervicente | 0:8a1a447db446 | 30 | */ |
javiervicente | 0:8a1a447db446 | 31 | |
javiervicente | 0:8a1a447db446 | 32 | class HCSR04 |
javiervicente | 0:8a1a447db446 | 33 | { |
javiervicente | 0:8a1a447db446 | 34 | public: |
javiervicente | 0:8a1a447db446 | 35 | /** Create a HCSR04 object connected to the specified pin |
javiervicente | 0:8a1a447db446 | 36 | * @param pin i/o pin to connect to |
javiervicente | 0:8a1a447db446 | 37 | */ |
javiervicente | 0:8a1a447db446 | 38 | HCSR04(PinName TrigPin,PinName EchoPin); |
javiervicente | 0:8a1a447db446 | 39 | ~HCSR04(); |
javiervicente | 0:8a1a447db446 | 40 | |
javiervicente | 0:8a1a447db446 | 41 | /** Return the distance from obstacle in cm |
javiervicente | 0:8a1a447db446 | 42 | * @param distance in cms and returns -1, in case of failure |
javiervicente | 0:8a1a447db446 | 43 | */ |
javiervicente | 0:8a1a447db446 | 44 | unsigned int get_dist_cm(void); |
javiervicente | 0:8a1a447db446 | 45 | /** Return the pulse duration equal to sonic waves travelling to obstacle and back to receiver. |
javiervicente | 0:8a1a447db446 | 46 | * @param pulse duration in microseconds. |
javiervicente | 0:8a1a447db446 | 47 | */ |
javiervicente | 0:8a1a447db446 | 48 | unsigned int get_pulse_us(void); |
javiervicente | 0:8a1a447db446 | 49 | /** Generates the trigger pulse of 10us on the trigger PIN. |
javiervicente | 0:8a1a447db446 | 50 | */ |
javiervicente | 0:8a1a447db446 | 51 | void start(void ); |
javiervicente | 0:8a1a447db446 | 52 | void isr_rise(void); |
javiervicente | 0:8a1a447db446 | 53 | void isr_fall(void); |
javiervicente | 0:8a1a447db446 | 54 | void fall (void (*fptr)(void)); |
javiervicente | 0:8a1a447db446 | 55 | void rise (void (*fptr)(void)); |
javiervicente | 0:8a1a447db446 | 56 | |
javiervicente | 0:8a1a447db446 | 57 | |
javiervicente | 0:8a1a447db446 | 58 | |
javiervicente | 0:8a1a447db446 | 59 | private: |
javiervicente | 0:8a1a447db446 | 60 | |
javiervicente | 0:8a1a447db446 | 61 | Timer pulsetime; |
javiervicente | 0:8a1a447db446 | 62 | DigitalOut trigger; |
javiervicente | 0:8a1a447db446 | 63 | InterruptIn echo; |
javiervicente | 0:8a1a447db446 | 64 | unsigned int pulsedur; |
javiervicente | 0:8a1a447db446 | 65 | unsigned int distance; |
javiervicente | 0:8a1a447db446 | 66 | }; |
javiervicente | 0:8a1a447db446 | 67 | |
javiervicente | 0:8a1a447db446 | 68 | #endif |