Kenan Mahmutović Emrah Dautbegović

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002  
00003 BusOut displej(dp26,dp27,dp5,dp6,dp28,dp4,dp18);
00004 BusOut Cifra(dp23,dp24,dp25);
00005  DigitalOut tacka(dp17);
00006 int cifra[3]={0xB,0xD,0xE};
00007 
00008 int funkcija(int broj)
00009 {
00010     switch(broj)
00011     {
00012         case 0: return 64;
00013         case 1: return 121;
00014         case 2: return 36;
00015         case 3: return 48;
00016         case 4: return 25;
00017         case 5: return 18;
00018         case 6: return 2;
00019         case 7: return 120;
00020         case 8: return 0;
00021         case 9: return 16;
00022     }
00023     return -1;
00024 }
00025 
00026 InterruptIn taster1(dp1);
00027 InterruptIn taster2(dp2);
00028  
00029 //Timer desetinka;
00030 //Timer jedinica;
00031 //Timer desetica;
00032  
00033 Ticker osvjezavanje;
00034 Ticker desetinka;
00035 Timer debounce;
00036  
00037 bool s(false),stop(true);
00038 int b1(0),b2(0),b3(0),c(0);
00039  
00040 void f1(){
00041     if(!stop){
00042        b1++;
00043        if(b1==10){
00044             b1=0;
00045             b2++;
00046             if(b2==10){
00047                 b2=0;
00048                 b3++;
00049                 if(b3==10) b3=0;
00050             }
00051         } 
00052     }
00053 }
00054  
00055 void start(){
00056     if(debounce.read_ms()>200){
00057        if(!s){
00058             stop=false;
00059             s=true;
00060         }
00061         else{
00062             stop=true;
00063             s=false; 
00064         } 
00065     }
00066     debounce.reset();
00067 }
00068  
00069 void reset(){
00070     stop=true;
00071     b1=0;
00072     b2=0;
00073     b3=0;
00074     s=false;   
00075 }
00076  
00077 void osvjezi(){
00078     Cifra=0xF;
00079      
00080     if(c==0){
00081         displej=funkcija(b1);
00082     }
00083     else if(c==1){
00084         displej=funkcija(b2);
00085         tacka=0;
00086        
00087     }
00088     else{
00089         tacka=1;
00090         displej=funkcija(b3);
00091     }
00092     Cifra=cifra[c];
00093     c++;
00094     if(c==3) c=0;
00095 }
00096  
00097  
00098  
00099 int main() {
00100     debounce.start();
00101     taster1.rise(&start);
00102     taster2.rise(&reset);
00103     desetinka.attach(&f1,0.1);
00104     osvjezavanje.attach(&osvjezi,0.001);
00105     while(1) {
00106         
00107     }
00108 }