sls

Dependencies:   mbed

Committer:
yuto17320508
Date:
Mon Apr 29 07:02:33 2019 +0000
Revision:
4:96f38805f055
Parent:
0:c1476d342c13
ss

Who changed what in which revision?

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