Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXOS8700CQ SDFileSystem mbed
Diff: my_libraries/ultrasonic.cpp
- Revision:
- 2:94059cb643be
- Child:
- 3:bd16e43ad7be
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/my_libraries/ultrasonic.cpp Thu Oct 16 17:30:52 2014 +0000
@@ -0,0 +1,29 @@
+// ----- Libraries ------------------------------------------------------------------
+#include "mbed.h"
+#include "ultrasonic.h"
+
+// ----- Constants ------------------------------------------------------------------
+#define ULTRA_R 1
+#define ULTRA_L 2
+
+// ----- I/O Pins -------------------------------------------------------------------
+AnalogIn ultra_lef(A2);
+AnalogIn ultra_rig(A3);
+
+// ----- Others ---------------------------------------------------------------------
+
+
+// ----- Variables ------------------------------------------------------------------
+double read_sensor, cm;
+
+// ----- Functions ------------------------------------------------------------------
+float ultrasonicos(int sensor){
+ if (sensor == ULTRA_R) {
+ read_sensor = ultra_rig; // read analog as a float
+ }else if (sensor == ULTRA_L) {
+ read_sensor = ultra_lef; // read analog as a float
+ }
+ // read_sensor * 3300mv / 6.4 mV/in * 2.54 in/cms
+ cm = read_sensor * 1309.6875;
+ return cm;
+}
\ No newline at end of file