Proof of concept for distance and temperature monitoring

Dependencies:   mbed mbedConnectorInterface mbedEndpointNetwork

Committer:
Luminoscity
Date:
Fri May 01 23:21:36 2015 +0000
Revision:
0:cb422b231ea5
Child:
8:c69fe28366d8
Demo Temp and Distance Program;

Who changed what in which revision?

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