ADC & DAC Analog
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 00003 00004 DigitalOut Vcc(PA_0); 00005 AnalogIn aInn(PA_1); 00006 DigitalOut Gnd(PA_4); 00007 00008 00009 int main() 00010 { 00011 Vcc = 1; 00012 Gnd = 0; 00013 00014 float maxVoltage,minVoltage,voltagePrv; 00015 00016 maxVoltage = minVoltage = aInn.read()*3.3f; 00017 00018 while(1) 00019 { 00020 float voltage; 00021 for(int i = 0; i < 1000; i++) 00022 { 00023 voltage += aInn.read()*3.3f; 00024 } 00025 00026 voltage = voltage/1000; 00027 if(voltage < voltagePrv - 0.3f || voltage > voltagePrv + 0.3f) 00028 { 00029 voltagePrv = voltage; 00030 if(voltage < minVoltage) minVoltage = voltage; 00031 if(voltage > maxVoltage)maxVoltage = voltage; 00032 00033 printf("VoltIn: %.3f Max: %.3f Min: %.3f Diff: %.3f\r\n", voltage, maxVoltage, minVoltage, maxVoltage-minVoltage); 00034 } 00035 // printf("Voltage:\t%.3f \r\n", voltage); 00036 wait_ms(135); 00037 } 00038 00039 00040 }
Generated on Fri Jul 15 2022 20:06:39 by
1.7.2