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: mbed
Diff: distanceSensors.cpp
- Revision:
- 0:e1e981676769
- Child:
- 1:558bf026649c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/distanceSensors.cpp Thu Mar 09 21:15:35 2017 +0000
@@ -0,0 +1,45 @@
+#include <cmath>
+#include "Distance_Sensors.h"
+
+
+
+DistanceSensors::DistanceSensors()
+{
+}
+
+DistanceSensors::DistanceSensors(AnalogIn* sensorVoltage, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number)
+{
+ init(sensorVoltage, bit0, bit1, bit2, number);
+}
+
+//initialise
+void DistanceSensors::init(AnalogIn* sensorVoltage, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number)
+{
+ this->sensorVoltage = sensorVoltage;
+ this->bit0 = bit0;
+ this->bit1 = bit1;
+ this->bit2 = bit2;
+}
+
+
+DistanceSensors::~DistanceSensors()
+{
+}
+
+
+float DistanceSensors::read()//Return the distance of an object
+{
+ *bit0 = number & 1; // Set the first bit of the Sensors MUX
+ *bit1 = number & 2; // Set the second bit of the Sensors MUX
+ *bit2 = number & 4; // Set the third bit of the Sensors MUX
+
+float Usensor=sensorVoltage->read(); //Read the Voltage from the selected distance sensor
+float Distance=-0.38f*sqrt(Usensor)+0.38f;
+ return Distance;
+}
+
+DistanceSensors::operator float()
+{
+ return read();
+}
+