Drittoppgaven

Dependencies:   mbed

main.cpp

Committer:
Voldread
Date:
2015-10-08
Revision:
0:cd965f803ca2

File content as of revision 0:cd965f803ca2:

#include "mbed.h"

DigitalOut Vcc(PA_0);
AnalogIn aInn(PA_1);
DigitalOut Gnd(PA_4);

int main() 
{   
    Vcc=1;
    Gnd=0;
    int i;
    float voltage, maxVoltage, minVoltage, avgV, sum;
    
    maxVoltage = minVoltage=aInn.read()*3.3f;
    while(1)
    {
       
        for(i=0;i<1000;i++)
        {
        voltage=aInn.read()*3.3f;           
        } 
        sum=(sum+voltage)/1000;  
        
        if(voltage<maxVoltage)
        maxVoltage=voltage;
        
        if(voltage>minVoltage)
        minVoltage=voltage;
        
        printf("AvgV: %.3f Curent: %.3f Min: %.3f Max: %.3f Max-Min: %.3f\r\n",sum, voltage, maxVoltage, minVoltage, maxVoltage-minVoltage);
        wait_ms(500);
    }
}