prog1

Committer:
altoimperatore
Date:
Wed Mar 27 11:10:39 2019 +0000
Revision:
0:78ba4d247714
prog

Who changed what in which revision?

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