zh mg
/
Nucleo_AnalogIn
NUCLEO-F103 ADC example
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 AnalogIn light(A0); 00003 DigitalOut led(LED1); 00004 00005 float lvf=0; 00006 float lvu=0; 00007 int main() 00008 { 00009 while(1) 00010 { 00011 lvf=(float)light; 00012 lvu=light.read();// Converts and read the analog input value (value from 0.0 to 1.0) 00013 lvu = lvu * 3300;// Change the value to be in the 0 to 3300 range 00014 printf("light adc count is %f , %.0fmV \n",lvf,lvu); 00015 wait(0.5); 00016 if (lvu<0.7)// If the value is less than 0.7V then switch the LED on 00017 led=1; 00018 else 00019 led=0; 00020 } 00021 00022 }
Generated on Wed Jul 13 2022 02:14:24 by 1.7.2