ECE595 - Lab 3 Part 2 - 4-Digit Display Program - TA

Dependencies:   DigitDisplay

Files at this revision

API Documentation at this revision

Comitter:
priyank12p
Date:
Sat Jan 16 00:47:35 2021 +0000
Parent:
0:4cb6e9d0da34
Commit message:
Initial Commit

Changed in this revision

DigitDisplay.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
diff -r 4cb6e9d0da34 -r 93e233c997ad DigitDisplay.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DigitDisplay.lib	Sat Jan 16 00:47:35 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/pruek/code/DigitDisplay/#b593c32bb21f
diff -r 4cb6e9d0da34 -r 93e233c997ad main.cpp
--- a/main.cpp	Fri Jan 15 23:55:27 2021 +0000
+++ b/main.cpp	Sat Jan 16 00:47:35 2021 +0000
@@ -1,19 +1,53 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2019 ARM Limited
- * SPDX-License-Identifier: Apache-2.0
- */
+#include "mbed.h"
+#include "DigitDisplay.h"
+
+DigitalOut myled(LED1);
 
-#include "mbed.h"
+DigitDisplay display(D2, D3);
+
+Ticker tick;
 
-DigitalIn button(D6);
+uint8_t hour   = 20;
+uint8_t minute = 14;
+uint8_t second = 0;
 
-int main()
+void beat()
 {
-    while(1){
-        if(button){
-            printf("Button Pressed\n\r");
-            wait(0.7); // simple debouncing
-        }           
+    static uint8_t colon = 0;
+    display.setColon(colon);
+    if (colon) {
+        second++;
+        if (second >= 60) {
+            second = 0;
+            minute++;
+            if (minute >= 60) {
+                minute = 0;
+                
+                hour++;
+                if (hour >= 24) {
+                    hour = 0;
+                }
+                display.write(0, hour / 10);
+                display.write(1, hour % 10);
+            }
+            display.write(2, minute / 10);
+            display.write(3, minute % 10);
+        }
     }
+    colon = 1 - colon;
+}
 
-}
+int main() {
+    display.write(0, hour / 10);
+    display.write(1, hour % 10);
+    display.write(2, minute / 10);
+    display.write(3, minute % 10);
+    display.setColon(true);
+    tick.attach(&beat, 0.5);
+    while(1) {
+        myled = 1;
+        wait(0.5);
+        myled = 0;
+        wait(0.5);
+    }
+}
\ No newline at end of file