Buggy bois / Mbed 2 deprecated headache

Dependencies:   mbed

Revision:
3:01b5e80d842d
Parent:
1:813f4b17ae65
Child:
4:208f5279143a
--- a/SensorControl/lineSensor.h	Sun Mar 03 00:55:10 2019 +0000
+++ b/SensorControl/lineSensor.h	Sat Mar 09 14:27:48 2019 +0000
@@ -2,18 +2,20 @@
 {
     
     private:
+    
     DigitalOut emitter;
     AnalogIn receiver;
     float static const vREF = 3.3f;
-    Timeout sampleTime;
     float lineVoltage;
+    Timeout sampler;
     
     public:
+    float static const sampleTime = 0.1f;
     
     lineSensor(PinName E, PinName R):emitter(E), receiver(R)
     {   
-       sampleTime.detach();
-    }
+        sampler.detach();
+    } 
     
     //Turn on the emitter i.e emit a light
     void turnOn(void)
@@ -39,10 +41,16 @@
         return emitter.read();
     }
     
+    void sample(void)
+    {
+        turnOn();
+        sampler.attach(callback(this, &lineSensor::turnOff),sampleTime);
+        calcLineVoltage();
+    }
+    
     void calcLineVoltage(void)
     {
         lineVoltage = receiver.read() * vREF;
-        turnOff();
     }
     
     float returnLineVoltage(void)
@@ -50,10 +58,4 @@
      return lineVoltage;
     }
     
-    void takeReading()
-    {
-        turnOn();
-        sampleTime.attach(callback(this, &lineSensor::calcLineVoltage),0.09); //time till turn off
-    }
-    
 };
\ No newline at end of file