h

Dependents:   frdm_rtos frdm_gpiokath Sumo

Committer:
lavioros
Date:
Wed Jan 09 19:24:29 2019 +0000
Revision:
0:4947ffc8c310
hh

Who changed what in which revision?

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