ADC & DAC Analog

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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;
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         
00028         if(voltage < minVoltage) minVoltage = voltage;
00029         if(voltage > maxVoltage)maxVoltage = voltage;
00030         
00031         if(voltage <= 1.0f)
00032         {
00033             printf("Spening - %.3f :For lav spenning \r\n\n", voltage ); 
00034         }
00035         else if(voltage >= 1.0f && voltage <= 2.0f) 
00036         {
00037             printf("Spening - %.3f :Rikig spenning \r\n\n", voltage ); 
00038         }
00039         else if(voltage >= 2.0f) 
00040         {
00041             printf("Spening - %.3f :For hoy spenning \r\n\n", voltage );
00042         }
00043         
00044         //printf("VoltIn: %.3f  Max: %.3f  Min: %.3f  Diff: %.3f\r\n", voltage, maxVoltage, minVoltage, maxVoltage-minVoltage);
00045         
00046        // printf("Voltage:\t%.3f \r\n", voltage);
00047         wait_ms(200);
00048     }
00049         
00050     
00051 }