simplify version, but need 3.3v for the photodiode

Dependencies:   mbed

Fork of Nucleo_read_analog_value by Robocon_IPS

Revision:
0:f3b9844205f2
Child:
1:5bc3306dd478
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed May 31 12:15:01 2017 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+ 
+AnalogIn analog_value(PA_0);
+ 
+DigitalOut led(LED1);
+Serial pc(USBTX,USBRX,115200);
+Timer t;
+
+int main() {
+    pc.format(8,SerialBase::None,1);
+    float meas;
+    led = 1;
+    pc.printf("\nAnalogIn example\n");
+    float max, min, mean;
+    max = analog_value.read()*3300;
+    min = max;
+    
+    
+    while(1) {
+        meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+        meas = meas * 3300; // Change the value to be in the 0 to 3300 range
+        if (meas>max)
+            max = meas;
+        if (meas<min)
+            min = meas;
+        mean = (max + min)/2;
+        pc.printf("measure = %.0f mV, mean = %.0f mV\n", meas, mean);
+        if (meas < mean) { // If the value is greater than 2V then switch the LED on
+          t.start();
+          while(analog_value.read()*3300 < mean);
+          t.stop();
+          //if(t.read() > 0.00001)
+          pc.printf("The time taken was %f seconds\n", t.read());
+          wait(1);
+        }
+        t.reset();
+    }
+}