dad

Dependencies:   mbed-os FXAS21000 LED_Bar FXOS8700Q

Committer:
mukundy8
Date:
Wed Apr 27 00:22:09 2022 +0000
Revision:
4:91893b37450e
Parent:
2:d08625231a9f
final;

Who changed what in which revision?

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