Analog Input example for WIZWiki-W7500 Academy

Dependencies:   mbed

Fork of AnalogIn_HelloWorld_WIZwiki-W7500 by Lawrence Lee

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Analog Input Example Program */
00002  
00003 #include "mbed.h"
00004 
00005 DigitalOut myled_R(LED_RED);
00006 
00007 AnalogIn ain(A0);     
00008 
00009 
00010 int main(void)
00011 {   
00012     int ain_val = 0;
00013     
00014     while (1) {
00015         
00016         ain_val = ain.read()*1000;
00017             
00018         // Compare between 'Specific value' and 'Analog Input value'
00019         if(ain_val > 500)  
00020         {
00021             myled_R = 1;      // Red LED OFF
00022         }
00023         else    
00024         {
00025             myled_R = 0;      // Red LED ON
00026         }
00027         
00028         // output the voltage and analog values
00029         printf("======================\r\n");
00030         printf("voltage value : %3.3f\r\n", ain.read()*3.3f);   // voltage 0.0V ~ 3.3V
00031         printf("analog value : %3.3f\r\n", ain.read());         // analog value 0.0 ~ 1.0
00032         printf("analog value x1000 : %d\r\n",ain_val);          // analog value 0 ~ 1000
00033         wait(1.0);
00034     }
00035 }
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044