l

Dependencies:   mbed

Committer:
yuto17320508
Date:
Sat Apr 27 11:22:00 2019 +0000
Revision:
6:75cfa1a66382
Parent:
0:111abd91b0cb
l

Who changed what in which revision?

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