A digital clock using Grove - 4 Digit Display

Dependencies:   DigitDisplay mbed

Fork of Arch_Digit_Display by Yihui Xiong

Files at this revision

API Documentation at this revision

Comitter:
yihui
Date:
Wed Aug 20 08:35:13 2014 +0000
Parent:
0:89330707469d
Commit message:
Digital Clock

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 89330707469d -r f45925081128 main.cpp
--- a/main.cpp	Mon Apr 28 00:59:56 2014 +0000
+++ b/main.cpp	Wed Aug 20 08:35:13 2014 +0000
@@ -4,12 +4,40 @@
 DigitDisplay display(P1_14, P1_13); // 4-Digit Display connected to UART Grove connector
 DigitalOut   led(LED1);
 
-int main() {
-    int count = 0;
-    while(1) {
-        display = count;
-        count++;
-        led = !led;
-        wait(1);
+Ticker ticker;
+volatile uint8_t second = 0;
+volatile uint8_t minute = 0;
+volatile uint8_t hour = 12;
+volatile bool colon_enable = false;
+
+void tick()
+{
+    colon_enable = !colon_enable;
+    display.setColon(colon_enable);
+    
+    if (colon_enable) {
+        second++;
+        if (second >= 60) {
+            second = 0;
+            minute++;
+            if (minute >= 60) {
+                minute = 0;
+                hour++;
+                if (hour >= 24) {
+                    hour = 0;
+                }
+            }
+            
+            display.write(hour * 100 + minute);
+        }
     }
 }
+
+int main() {
+    display.write(hour * 100 + minute);
+    ticker.attach(tick, 0.5);
+    while(1) {
+        led = !led;
+        wait(0.5);
+    }
+}
diff -r 89330707469d -r f45925081128 mbed.bld
--- a/mbed.bld	Mon Apr 28 00:59:56 2014 +0000
+++ b/mbed.bld	Wed Aug 20 08:35:13 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file