Demirović Tarik Čilić Zlatan

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 int cifre[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x078,0x0,0x10};
00004  
00005 BusOut enable(dp23,dp24,dp25);
00006 BusOut display(dp26, dp27, dp5, dp6, dp28, dp4, dp18);
00007 DigitalOut point(dp17);
00008 
00009 InterruptIn t1(dp1);
00010 InterruptIn t2(dp2);
00011 int cifra1(cifre[0]);
00012 int cifra2(cifre[0]);
00013 int cifra3(cifre[0]);
00014 int izborCifre(3);
00015 Timer timer1;
00016 Ticker ticker1;
00017 Ticker ticker2;
00018 Timer debounce;
00019 Timer debounce1;
00020 
00021 bool on;
00022 
00023 void inkrementiraj()
00024 {
00025     float broj = timer1.read();
00026     
00027     cifra3 = int((broj - int(broj))*10);
00028     cifra2 = int(broj) % 10;
00029     cifra1 = int(broj) / 10;
00030 }
00031 
00032 void osvjezi()
00033 {
00034    if(izborCifre == 3)
00035    {
00036         enable = izborCifre;
00037         display = cifre[cifra3];
00038         izborCifre = 5;
00039    }
00040    else if(izborCifre == 5)
00041    {
00042         enable = izborCifre;
00043         point = 0;
00044         display = cifre[cifra2];
00045         izborCifre = 6;
00046    }
00047    else
00048    {
00049         point = 1;
00050         enable = izborCifre;
00051         display = cifre[cifra1];
00052         izborCifre = 3;
00053    }
00054 }
00055 
00056 void startstop()
00057 {
00058     if(debounce.read_ms() > 400)
00059     {
00060         if(on) timer1.stop();
00061         else timer1.start();
00062         on = !on;     
00063         debounce.reset();
00064     }
00065 }
00066 
00067 void resetfunc()
00068 {
00069     if(debounce1.read_ms() > 400)
00070     {
00071         timer1.reset();
00072         timer1.stop();
00073         debounce1.reset();
00074     }
00075 }
00076 
00077 int main() {
00078     enable = 0;
00079     display = 0x40;
00080     debounce.start();
00081     debounce1.start();
00082     ticker1.attach(&osvjezi, 0.005);
00083     ticker2.attach(&inkrementiraj, 0.1);
00084     timer1.start();
00085     on = true;
00086     t1.rise(&startstop);
00087     t2.rise(&resetfunc);
00088     while(1) {
00089     }
00090 }