Drittoppgaven

Dependencies:   mbed

Committer:
Voldread
Date:
Thu Oct 08 16:20:51 2015 +0000
Revision:
0:cd965f803ca2
Drittoppgaven

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Voldread 0:cd965f803ca2 1 #include "mbed.h"
Voldread 0:cd965f803ca2 2
Voldread 0:cd965f803ca2 3 DigitalOut Vcc(PA_0);
Voldread 0:cd965f803ca2 4 AnalogIn aInn(PA_1);
Voldread 0:cd965f803ca2 5 DigitalOut Gnd(PA_4);
Voldread 0:cd965f803ca2 6
Voldread 0:cd965f803ca2 7 int main()
Voldread 0:cd965f803ca2 8 {
Voldread 0:cd965f803ca2 9 Vcc=1;
Voldread 0:cd965f803ca2 10 Gnd=0;
Voldread 0:cd965f803ca2 11 int i;
Voldread 0:cd965f803ca2 12 float voltage, maxVoltage, minVoltage, avgV, sum;
Voldread 0:cd965f803ca2 13
Voldread 0:cd965f803ca2 14 maxVoltage = minVoltage=aInn.read()*3.3f;
Voldread 0:cd965f803ca2 15 while(1)
Voldread 0:cd965f803ca2 16 {
Voldread 0:cd965f803ca2 17
Voldread 0:cd965f803ca2 18 for(i=0;i<1000;i++)
Voldread 0:cd965f803ca2 19 {
Voldread 0:cd965f803ca2 20 voltage=aInn.read()*3.3f;
Voldread 0:cd965f803ca2 21 }
Voldread 0:cd965f803ca2 22 sum=(sum+voltage)/1000;
Voldread 0:cd965f803ca2 23
Voldread 0:cd965f803ca2 24 if(voltage<maxVoltage)
Voldread 0:cd965f803ca2 25 maxVoltage=voltage;
Voldread 0:cd965f803ca2 26
Voldread 0:cd965f803ca2 27 if(voltage>minVoltage)
Voldread 0:cd965f803ca2 28 minVoltage=voltage;
Voldread 0:cd965f803ca2 29
Voldread 0:cd965f803ca2 30 printf("AvgV: %.3f Curent: %.3f Min: %.3f Max: %.3f Max-Min: %.3f\r\n",sum, voltage, maxVoltage, minVoltage, maxVoltage-minVoltage);
Voldread 0:cd965f803ca2 31 wait_ms(500);
Voldread 0:cd965f803ca2 32 }
Voldread 0:cd965f803ca2 33 }