El-POM1001 / Mbed 2 deprecated LAB06_Oppgave3

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         printf("VoltIn: %.3f  Max: %.3f  Min: %.3f  Diff: %.3f\r\n", voltage, maxVoltage, minVoltage, maxVoltage-minVoltage);
00032         
00033        // printf("Voltage:\t%.3f \r\n", voltage);
00034         wait_ms(135);
00035     }
00036         
00037     
00038 }