Josip Kvesić

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 cifra(dp23,dp24,dp25);
00004 BusOut broj(dp18,dp4,dp28,dp6,dp5,dp27,dp26);
00005 DigitalOut tacka(dp17);
00006 int segmenti[10] = {0x01, 0x4f, 0x12, 0x06, 0x4c,0x24, 0x20, 0x0f, 0x00, 0x04};
00007 InterruptIn taster1(dp1);
00008 InterruptIn taster2(dp2);
00009  
00010 bool stop(true);
00011 Timer t,t1,t2,t3;
00012 Ticker ticker,ticker1;
00013 int i=0;
00014 
00015 void pomocna(int b)
00016 {
00017     if(b>=0 && b<=9)
00018     broj=segmenti[b];
00019     else 
00020     broj=0x7f;
00021  }   
00022 
00023 
00024 
00025  
00026  
00027 void display()
00028 {
00029     
00030     float  vrijeme=t.read();
00031  
00032   int cifre[3]={ (int)(vrijeme / 10.) % 10,(int)(vrijeme) % 10,(int)(vrijeme* 10.) % 10};
00033 
00034   for( i=1;i<=4;i=i*2)
00035   {
00036         cifra=~i;
00037       pomocna(cifre[i/2]);
00038       if(i==2)
00039       tacka=0;
00040       else tacka=1;
00041        t3.start();
00042        while(t3.read_ms()<1);
00043        t3.reset();
00044        t3.stop();
00045      
00046        cifra=7;
00047       }
00048   
00049  
00050 }
00051  
00052  
00053 void start_stop()
00054 {
00055  
00056   if(t1.read_ms()>200){
00057         if(stop){
00058          t.start();
00059          stop = false;
00060          }
00061         else if (!stop){
00062             t.stop();
00063             stop = true;
00064         }
00065  
00066         t1.reset();     
00067     }
00068     
00069     }
00070  
00071 void reset()
00072 {
00073  
00074   if(t2.read_ms() > 200) {
00075         t.reset();
00076         t.stop();
00077         stop = true;
00078       
00079         t2.reset();
00080     }
00081  
00082 }
00083  
00084  
00085  
00086  
00087  
00088 int main() 
00089 {
00090     t1.start();
00091     t2.start();
00092     ticker.attach_us(&display,5000);
00093     taster1.rise(&start_stop);
00094     taster2.rise(&reset);
00095     while(1) 
00096     {
00097     
00098     }
00099 }
00100