hi

Dependencies:   mbed TM1636 RTC-DS1307

Files at this revision

API Documentation at this revision

Comitter:
jobtanadol
Date:
Tue Dec 18 21:33:16 2018 +0000
Parent:
4:051852f988eb
Commit message:
job

Changed in this revision

RTC-DS1307.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/RTC-DS1307.lib	Tue Dec 18 09:34:52 2018 +0000
+++ b/RTC-DS1307.lib	Tue Dec 18 21:33:16 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/jobtanadol/code/RTC-DS1307/#cac498d0a71d
+https://os.mbed.com/users/jobtanadol/code/RTC-DS1307/#4f0f1da66cfb
--- a/main.cpp	Tue Dec 18 09:34:52 2018 +0000
+++ b/main.cpp	Tue Dec 18 21:33:16 2018 +0000
@@ -2,18 +2,22 @@
 #include "Rtc_Ds1307.h"
 #include "TM1636.h"
 
-//RtcCls rtc(p28, p27, p29, true);
-Rtc_Ds1307 rtc(D3, D6);
-DigitalIn  button_K3(A5);
-TM1636 tm1636(D7,D8);  
+
+Rtc_Ds1307 rtc(D3, D6);//sda/sci
+DigitalIn  button_K1(A5);
+DigitalIn  button_K2(A4);
+DigitalIn  button_K3(USER_BUTTON);
+TM1636 tm1636(D7,D8); //clk/data 
 Serial pc(USBTX, USBRX, "pc");
 
-//char buffer[128];
-//int readptr = 0;
 
 int main() {
 int8_t temp[4];
-    button_K3.mode(PullUp);
+int job[3];
+int total[3];
+int8_t run[4];
+    button_K1.mode(PullUp);
+    button_K2.mode(PullUp);
     tm1636.init();
     Rtc_Ds1307::Time_rtc tm = {};
     tm.date = 1 ;
@@ -25,14 +29,43 @@
     rtc.setTime(tm, false, false);
     rtc.startClock();
     while(1) {
-            
+            if(button_K2){
             rtc.getTime(tm);
             pc.printf("%02d:%02d:%02d\n",tm.hour,tm.min,tm.sec);
-            temp[0] = tm.hour / 10;
-            temp[1] = tm.hour % 10;
-            temp[2] = tm.min / 10;
-            temp[3] = tm.min % 10;                 
-            tm1636.display(temp);  
+            temp[0] = tm.min / 10;
+            temp[1] = tm.min % 10;
+            temp[2] = tm.sec / 10;
+            temp[3] = tm.sec % 10;                 
+            tm1636.display(temp);
+            } 
+            if (!button_K1){
+            rtc.stopClock();
+            pc.printf("%02d:%02d:%02d\n",tm.hour,tm.min,tm.sec);
+            wait(0.05);
+            rtc.getTime(tm);
+            job[0] = tm.hour;
+            job[1] = tm.min;
+            job[2] = tm.sec; 
+            rtc.startClock();
+            }
+            pc.printf("%02d:%02d:%02d++++++++++++++++++++++\n",job[0],job[1],job[2]);
+            if (!button_K2){
+                total[0]=tm.hour-job[0];
+                total[1]=tm.min-job[1];
+                total[2]=tm.sec-job[2];
+                run[0]=total[1]/10;
+                run[1]=total[1]%10;
+                run[2]=total[2]/10;
+                run[3]=total[2]%10 ;
+                tm1636.display(run);
+                wait(0.4);
+                
+                }
+            
+            if (button_K3==0){
+                rtc.stopClock();
+                
+                }
             
             }
             }