Hadzic Muharem Haris Šemić

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 Broj(dp17,dp18,dp4,dp28,dp6,dp5,dp27,dp26);
00004 BusOut Cifra(dp23,dp24,dp25);
00005 
00006 int broj[10]={0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09};
00007 int brojDP[10]={0x02,0x9E,0x24,0x0C,0x98,0x48,0x40,0x1E,0x00,0x08};
00008 int cifra[3]={0xB,0xD,0xE};
00009 
00010 InterruptIn taster1(dp1);
00011 InterruptIn taster2(dp2);
00012 
00013 //Timer desetinka;
00014 //Timer jedinica;
00015 //Timer desetica;
00016 
00017 Ticker osvjezavanje;
00018 Ticker desetinka;
00019 Timer debounce;
00020 
00021 bool s(false),stop(true);
00022 int b1(0),b2(0),b3(0),c(0);
00023 
00024 void f1(){
00025     if(!stop){
00026        b1++;
00027        if(b1==10){
00028             b1=0;
00029             b2++;
00030             if(b2==10){
00031                 b2=0;
00032                 b3++;
00033                 if(b3==10) b3=0;
00034             }
00035         } 
00036     }
00037 }
00038 
00039 void start(){
00040     if(debounce.read_ms()>200){
00041        if(!s){
00042             stop=false;
00043             s=true;
00044         }
00045         else{
00046             stop=true;
00047             s=false; 
00048         } 
00049     }
00050     debounce.reset();
00051 }
00052 
00053 void reset(){
00054     stop=true;
00055     b1=0;
00056     b2=0;
00057     b3=0;
00058     s=false;   
00059 }
00060 
00061 void osvjezi(){
00062     Cifra=0xF;
00063     if(c==0){
00064         Broj=broj[b1];
00065     }
00066     else if(c==1){
00067         Broj=brojDP[b2];
00068     }
00069     else{
00070         Broj=broj[b3];
00071     }
00072     Cifra=cifra[c];
00073     c++;
00074     if(c==3) c=0;
00075 }
00076 
00077 
00078 
00079 int main() {
00080     debounce.start();
00081     taster1.rise(&start);
00082     taster2.rise(&reset);
00083     desetinka.attach(&f1,0.1);
00084     osvjezavanje.attach(&osvjezi,0.001);
00085     while(1) {
00086         
00087     }
00088 }