haris Čustović luka pejović

Dependencies:   mbed

Fork of LV3_Grupa4_Tim010_zadatak2 by tim010 tim010

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002  
00003 
00004 
00005 DigitalOut red1(dp16), red2(dp15), red3(dp17), red4(dp18);
00006 DigitalIn kol1(dp9), kol2(dp10), kol3(dp11), kol4(dp13);
00007  
00008 DigitalOut cifre[3] = {dp23, dp24, dp25};
00009 BusOut disp(dp4, dp2, dp1, dp28, dp6, dp5, dp27, dp26);
00010 
00011 
00012 int _7sd(char znak, bool tocka = false)
00013 {
00014     //za sljedeci raspored: a b c d e f g dp
00015     //a to su dp26 dp27 dp5 dp6 dp28 dp1 dp2 dp4
00016     int t = !tocka;
00017     switch(znak)
00018     {
00019         case 'N':
00020             return 0xfe | t;
00021         case '0':
00022             return 0x02 | t;
00023         case '1':
00024             return 0x9e | t;
00025         case '2':
00026             return 0x24 | t;
00027         case '3':
00028             return 0x0c | t;
00029         case '4':
00030             return 0x98 | t;
00031         case '5':
00032             return 0x48 | t;
00033         case '6':
00034             return 0x40 | t;
00035         case '7':
00036             return 0x1a | t;
00037         case '8':
00038             return 0x00 | t;
00039         case '9':
00040             return 0x08 | t;
00041         case 'a': case 'A':
00042             return 0x10 | t;
00043         case 'b': case 'B':
00044             return 0xc0 | t;
00045         case 'c': case 'C':
00046             return 0x62 | t;
00047         case 'd': case 'D':
00048             return 0x84 | t;
00049         case 'e': case 'E':
00050             return 0x60 | t;
00051         case 'f': case 'F':
00052             return 0x70 | t;
00053         case '*':
00054             return 0x90 | t;
00055         case '#':
00056             return 0x6c | t;
00057     }
00058 }
00059 
00060 char ocitajtast()
00061 {
00062     red1 = 0; red2 = 0; red3 = 0; red4 = 0;
00063 
00064     
00065     red1 = 1;
00066     if( kol1 == 1) return '1';
00067     
00068     if( kol2 == 1) return '2';
00069    
00070     if( kol3 == 1) return '3';
00071     
00072     if(kol4 == 1) return 'A';
00073     
00074     red1 = 0;
00075     
00076     red2 = 1;
00077     if( kol1 == 1) return '4';
00078     if( kol2 == 1) return '5';
00079     if( kol3 == 1) return '6';
00080     if(kol4 == 1) return 'B';
00081     red2 = 0;
00082     
00083     red3 = 1;
00084     if( kol1 == 1) return '7';
00085     if( kol2 == 1) return '8';
00086     if( kol3 == 1) return '9';
00087     if(kol4 == 1) return 'C';
00088     red3 = 0;
00089     
00090     red4 = 1;
00091     if( kol1 == 1) return '*';
00092     if( kol2 == 1) return '0';
00093     if( kol3 == 1) return '#';
00094     if(kol4 == 1) return 'D';
00095     red4 = 0;
00096  
00097     return 'N';
00098 }
00099 
00100 void ispisi(char znakovi[] ){
00101     
00102     for(int i = 0; i < 3; i++){
00103         cifre[i] = 0;
00104         disp = _7sd(znakovi[i]);
00105         wait(0.0025);  
00106         cifre[i] = 1;
00107          
00108     }
00109 }
00110 
00111 char niz[3];
00112 
00113 void dodaj(char c){
00114     if(c == 'C'){
00115         for(int i = 0; i < 3; i++)
00116             niz[i] = 'N';   
00117     } else {
00118         niz[0] = niz[1];
00119         niz[1] = niz[2];
00120         niz[2] = c;
00121         
00122         if(niz[0] == '0') {
00123             niz[0] = 'N';
00124             if(niz[1] == '0')
00125                 niz[1] = 'N';   
00126         }
00127         
00128         if(niz[0] == 'N' && niz[1] == '0')
00129             niz[1] = 'N';
00130     }
00131 }
00132 
00133 int main() {
00134     char c, c1;
00135     int counter = 0;
00136     
00137     niz[0] = 'N';
00138     niz[1] = 'N';
00139     niz[2] = 'N';
00140     
00141     wait(1);
00142     niz[2] = '0';
00143     
00144     while(1){
00145            for(counter = 0; ;counter++)
00146            {
00147                 ispisi(niz);
00148                 c = ocitajtast();
00149                 if( c == 'N'){
00150                     break;   
00151                 }    
00152                 c1 = c;
00153                 //wait(0.12);
00154                 //dodaj(c);   
00155                 
00156                 
00157             }
00158             if (counter > 8)
00159             dodaj(c1); 
00160             
00161            
00162     }
00163     
00164 }