LV4_grupa7_Tim004_z4_AmarBasic_AdmiraHusic

Dependencies:   mbed

main.cpp

Committer:
pai2015admirahusic
Date:
2015-03-26
Revision:
0:9842b760e5d1

File content as of revision 0:9842b760e5d1:

#include <math.h>

#include "mbed.h"
#define dp23 P0_0


int izlazi[]= {64,121,36,48,25,18,2,120,0,16};
BusOut ledovi(dp26, dp27, dp5, dp6, dp28, dp1, dp2);
BusOut ukljuci(dp23,dp24,dp25);
int ukljucicifru[3]= {3,5,6};

BusOut tacka(dp4);
DigitalOut enable(dp14);
AnalogIn napon(dp9);
float max=1.8;
float min=0.3;
int cifre[3]= {127,127,127};
float predotpor=1000;

void osvjezi(int displej)
{
 int i=0;
    while(i!=3) {

        
        cifre[i]=displej%10;
        displej/=10;
        ledovi=izlazi[cifre[i]];
        ukljuci=ukljucicifru[i];
        if(i==1) tacka=0;
        else tacka=1;
        i++;
        wait(0.010 / 3);
        ledovi=255;
    }
}


float izracunajotpor(float temp)
{
    float R=1000;
    float B=3400;
    float T=298.15;
    return (R*exp(B*(-1/T+1/temp)));
}

float izracunajtemp(float otpor)
{
    float R=1000;
    float B=3400;
    float T=298.15;
    return B /(log(otpor/R)  + B/T)-273.15;
 //   return (1/(log(otpor/R)/B-1/T));
}

int main()
{
    int brojac = 0;
    float mintemp;
    float maxtemp;
    float minotpor=izracunajotpor(mintemp);
    float maxotpor=izracunajotpor(maxtemp);
    float min=minotpor/(predotpor+minotpor)*3.3;
    float max=maxotpor/(predotpor+maxotpor)*3.3;
    enable=1;
    int displej=0;
    tacka=1;
    float otpor=0;
    while(1) {
//otpor=(int)((napon-min)/(max-min)*(maxotpor-minotpor)*10);
     if(brojac%100 == 0) {   otpor=3.3*napon*predotpor / (3.3 - 3.3*napon);;
       osvjezi((int)(izracunajtemp(otpor)*10));}
        
        brojac++;
    }
}