Library for using HC SR04 module sensor.

Dependents:   LoRa

Committer:
haaspors
Date:
Wed Jun 08 10:15:44 2016 +0000
Revision:
0:dbd45b08936b
Initial import of HC-SR04 library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
haaspors 0:dbd45b08936b 1 /* HCSR04 - MBED library for Ultrasonic Ranging Module HC - SR04
haaspors 0:dbd45b08936b 2 * Copyright (C) 2016 Haakon Sporsheim <haakon.sporsheim@gmail.com>
haaspors 0:dbd45b08936b 3 *
haaspors 0:dbd45b08936b 4 * This library is free software; you can redistribute it and/or
haaspors 0:dbd45b08936b 5 * modify it under the terms of the GNU Lesser General Public
haaspors 0:dbd45b08936b 6 * License as published by the Free Software Foundation; either
haaspors 0:dbd45b08936b 7 * version 3.0 of the License, or (at your option) any later version.
haaspors 0:dbd45b08936b 8 *
haaspors 0:dbd45b08936b 9 * This library is distributed in the hope that it will be useful,
haaspors 0:dbd45b08936b 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
haaspors 0:dbd45b08936b 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
haaspors 0:dbd45b08936b 12 * Lesser General Public License for more details.
haaspors 0:dbd45b08936b 13 *
haaspors 0:dbd45b08936b 14 * You should have received a copy of the GNU Lesser General Public
haaspors 0:dbd45b08936b 15 * License along with this library.
haaspors 0:dbd45b08936b 16 * See the COPYING file at the root of the source repository.
haaspors 0:dbd45b08936b 17 */
haaspors 0:dbd45b08936b 18
haaspors 0:dbd45b08936b 19 #ifndef __HCSR04_H__
haaspors 0:dbd45b08936b 20 #define __HCSR04_H__
haaspors 0:dbd45b08936b 21
haaspors 0:dbd45b08936b 22 #include <mbed.h>
haaspors 0:dbd45b08936b 23
haaspors 0:dbd45b08936b 24 class HCSR04
haaspors 0:dbd45b08936b 25 {
haaspors 0:dbd45b08936b 26 public:
haaspors 0:dbd45b08936b 27 HCSR04(PinName pinTrig, PinName pinEcho);
haaspors 0:dbd45b08936b 28
haaspors 0:dbd45b08936b 29 void start(void (*cb)(uint32_t), float interval);
haaspors 0:dbd45b08936b 30 void stop(void);
haaspors 0:dbd45b08936b 31
haaspors 0:dbd45b08936b 32 private:
haaspors 0:dbd45b08936b 33 DigitalOut trig;
haaspors 0:dbd45b08936b 34 InterruptIn echo;
haaspors 0:dbd45b08936b 35 Ticker ticker;
haaspors 0:dbd45b08936b 36 Timer timer;
haaspors 0:dbd45b08936b 37 int timeEcho;
haaspors 0:dbd45b08936b 38
haaspors 0:dbd45b08936b 39 void (*cbUpdate)(uint32_t);
haaspors 0:dbd45b08936b 40
haaspors 0:dbd45b08936b 41 void update(void);
haaspors 0:dbd45b08936b 42 void echoRise(void);
haaspors 0:dbd45b08936b 43 void echoFall(void);
haaspors 0:dbd45b08936b 44 };
haaspors 0:dbd45b08936b 45
haaspors 0:dbd45b08936b 46 #endif /* __HCSR04_H__ */