simplify version, but need 3.3v for the photodiode
Dependencies: mbed
Fork of Nucleo_read_analog_value by
Diff: main.cpp
- Revision:
- 1:5bc3306dd478
- Parent:
- 0:f3b9844205f2
diff -r f3b9844205f2 -r 5bc3306dd478 main.cpp --- a/main.cpp Wed May 31 12:15:01 2017 +0000 +++ b/main.cpp Thu Jun 01 01:10:26 2017 +0000 @@ -1,38 +1,23 @@ #include "mbed.h" - -AnalogIn analog_value(PA_0); +InterruptIn sensor(PA_0); -DigitalOut led(LED1); Serial pc(USBTX,USBRX,115200); + Timer t; +void start() { + t.start(); +} + +void stop() { + t.stop(); + pc.printf("%f seconds\n", t.read()); + t.reset(); +} + 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(); - } + sensor.fall(&start); // voltage drops below 3.3v + sensor.rise(&stop); // voltage rises above 3.3v + while(1); }