Omerović Mirza Kurtović Ilma

Dependencies:   mbed

Fork of LV4-Grupa3-Tim008-Zadatak1 by tim008 tim008

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002  
00003 BusOut display(dp26, dp27, dp5, dp6, dp28, dp1, dp2);
00004 DigitalOut point(dp4);
00005 int numbers[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x078,0x0,0x10};
00006 
00007 BusOut digits(dp23,dp24,dp25);
00008  
00009 AnalogIn input(dp9);
00010 void showDigit(int input)
00011 {
00012     if(input>=0 && input<=9)
00013         display=numbers[input];
00014     else
00015         display=0x7f;
00016 }
00017  
00018  
00019 void displayValue(float value)
00020 {
00021     int third=(value-int(value))*10;
00022     int second=int(value)%10;
00023     int first=int(value)/10;
00024     
00025     digits=6;
00026     showDigit(first);
00027     wait_ms(1);
00028     digits=7;
00029     showDigit(second);    
00030     digits=5;
00031     wait_ms(1);
00032     digits=7;
00033     showDigit(third);
00034     digits=3;
00035     wait_ms(1);
00036     digits=0;  
00037 }
00038  
00039  
00040 int main() {
00041     float max_volt=2.1;
00042     float min_volt=0.7;
00043     float ratio=0;
00044     float diff_volt=max_volt-min_volt;
00045     float ain=input*3.3;
00046     int i=0;
00047     while(1) {
00048         if(i%100==0)
00049             ain=input*3.3;
00050             
00051         if(ain>=min_volt && ain<=max_volt)      
00052             ratio=1-(ain-min_volt)/diff_volt;
00053         else
00054             ratio=0;
00055         displayValue(ratio*100);
00056         i++;
00057     }
00058 }