Jakić Irma Kiselica Aldin

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