Use this repository for pilot an ultrasonic sensor

Fork of UltrasonicSensor by Daniele Briguglio

Revision:
0:8ca9f71b386d
Child:
1:9d56714c1119
diff -r 000000000000 -r 8ca9f71b386d UltrasonicSensor.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UltrasonicSensor.h	Mon Jan 15 20:35:11 2018 +0000
@@ -0,0 +1,62 @@
+/*
+  UltrasonicSensor.h - drive a distance sensor- Version 1.0.0
+  Copyright (c) 2018 Daniele Briguglio.  All right reserved.
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+*/
+
+/*
+  The methods are:
+
+   UltrasonicSensor - Class for manipulating Ultrasonic Sensor
+
+   attach(echo, trigger)  - Attaches a Ultrasonic Sensor to an i/o pin,
+   default pins are D9 for echo and D8 for trigger.
+ 
+   read()  - Read distance measured by the sensor. 
+ */
+
+#ifndef UltrasonicSensor_h
+#define UltrasonicSensor_h
+
+#include <mbed.h>
+
+namespace mbed {
+    
+class UltrasonicSensor {
+
+public:
+    /** Create a UltrasonicSensor connection to the specified pin
+     *
+     *  @param pin echo pin to connect to
+     *  @param pin trigger pin to connect to
+     */
+    UltrasonicSensor(PinName echo, PinName trigger);
+    
+    /** begin of reading
+     *
+     *  @param float set correction for the reader
+     */
+    void begin(float correction);
+    void begin(void);
+    
+    /** Return the reader
+     *
+     *  @returns float read the distance
+     */
+    float read(void);
+    
+protected:
+    void begin2(void);
+    DigitalOut _trigger;
+    DigitalIn  _echo;
+    int distance;
+    int corr;
+    Timer sonar;
+};
+}
+
+#endif
\ No newline at end of file