zh mg
/
Nucleo_AnalogIn
NUCLEO-F103 ADC example
Diff: main.cpp
- Revision:
- 0:debb5e9583ad
diff -r 000000000000 -r debb5e9583ad main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Dec 07 06:59:02 2015 +0000 @@ -0,0 +1,22 @@ +#include "mbed.h" +AnalogIn light(A0); +DigitalOut led(LED1); + +float lvf=0; +float lvu=0; +int main() +{ + while(1) + { + lvf=(float)light; + lvu=light.read();// Converts and read the analog input value (value from 0.0 to 1.0) + lvu = lvu * 3300;// Change the value to be in the 0 to 3300 range + printf("light adc count is %f , %.0fmV \n",lvf,lvu); + wait(0.5); + if (lvu<0.7)// If the value is less than 0.7V then switch the LED on + led=1; + else + led=0; + } + +}