![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Read an analog value using ADC.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "smooth.cpp" 00003 AnalogIn analog_value(PA_0); 00004 Serial pc(PA_11, PA_12);/* Serial6 tx rx */ 00005 DigitalOut myled(LED1); 00006 00007 // Calculate the corresponding acquisition measure for a given value in mV 00008 #define MV(x) ((0xFFF*x)/3300) 00009 00010 uint16_t pre_val; 00011 00012 int main() { 00013 while(1) { 00014 //pc.printf("POPIZDOVALI\r\n"); 00015 uint16_t meas = analog_value.read_u16(); // Converts and read the analog input value 00016 if (meas > MV(1000)) { // If the value is greater than 1000 mV toggle the LED 00017 myled = !myled; 00018 } 00019 wait(0.8); // 200 mssdfg 00020 //char c = pc.getc(); 00021 //if(c!='q') 00022 uint16_t val = 2;//meas/16; 00023 uint16_t pre_val = 3;//meas/16; 00024 //smooth(&val,&pre_val,3,5); 00025 int ert = &val; 00026 int ert2 = &pre_val; 00027 00028 smooth(ert,ert2,3,5); 00029 00030 pc.printf("value %f - %d\r\n",meas/0xFFFF*3.30000,meas/16); 00031 } 00032 }
Generated on Thu Jul 14 2022 04:16:13 by
![doxygen](doxygen.png)