
simplify version, but need 3.3v for the photodiode
Dependencies: mbed
Fork of Nucleo_read_analog_value by
main.cpp
- Committer:
- cc061495
- Date:
- 2017-05-31
- Revision:
- 0:f3b9844205f2
- Child:
- 1:5bc3306dd478
File content as of revision 0:f3b9844205f2:
#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(); } }