NUCLEO-F103 ADC example

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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 }