Kenan Mahmutović Emrah Dautbegović

Dependencies:   mbed

main.cpp

Committer:
tim003
Date:
2014-04-10
Revision:
0:284bd0ba2b21

File content as of revision 0:284bd0ba2b21:

#include "mbed.h"
 
BusOut displej(dp26,dp27,dp5,dp6,dp28,dp4,dp18);
BusOut Cifra(dp23,dp24,dp25);
 DigitalOut tacka(dp17);
int cifra[3]={0xB,0xD,0xE};

int funkcija(int broj)
{
    switch(broj)
    {
        case 0: return 64;
        case 1: return 121;
        case 2: return 36;
        case 3: return 48;
        case 4: return 25;
        case 5: return 18;
        case 6: return 2;
        case 7: return 120;
        case 8: return 0;
        case 9: return 16;
    }
    return -1;
}

InterruptIn taster1(dp1);
InterruptIn taster2(dp2);
 
//Timer desetinka;
//Timer jedinica;
//Timer desetica;
 
Ticker osvjezavanje;
Ticker desetinka;
Timer debounce;
 
bool s(false),stop(true);
int b1(0),b2(0),b3(0),c(0);
 
void f1(){
    if(!stop){
       b1++;
       if(b1==10){
            b1=0;
            b2++;
            if(b2==10){
                b2=0;
                b3++;
                if(b3==10) b3=0;
            }
        } 
    }
}
 
void start(){
    if(debounce.read_ms()>200){
       if(!s){
            stop=false;
            s=true;
        }
        else{
            stop=true;
            s=false; 
        } 
    }
    debounce.reset();
}
 
void reset(){
    stop=true;
    b1=0;
    b2=0;
    b3=0;
    s=false;   
}
 
void osvjezi(){
    Cifra=0xF;
     
    if(c==0){
        displej=funkcija(b1);
    }
    else if(c==1){
        displej=funkcija(b2);
        tacka=0;
       
    }
    else{
        tacka=1;
        displej=funkcija(b3);
    }
    Cifra=cifra[c];
    c++;
    if(c==3) c=0;
}
 
 
 
int main() {
    debounce.start();
    taster1.rise(&start);
    taster2.rise(&reset);
    desetinka.attach(&f1,0.1);
    osvjezavanje.attach(&osvjezi,0.001);
    while(1) {
        
    }
}