SSD541_HW12.2

Dependencies:   SLCD TSI mbed

Files at this revision

API Documentation at this revision

Comitter:
eseifert
Date:
Sun Nov 06 20:02:16 2016 +0000
Parent:
1:d82569d51964
Commit message:
for the (last?) time

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r d82569d51964 -r f9713d90a13c main.cpp
--- a/main.cpp	Sun Nov 06 18:25:53 2016 +0000
+++ b/main.cpp	Sun Nov 06 20:02:16 2016 +0000
@@ -39,8 +39,8 @@
 void initialize_global_vars()
 {
     pc.printf(PROGNAME);
+    pc.printf("Select count->\n\r");
     // set up DAQ timer
-    // set up DAQ timers
     ButtonTimer.start();
     ButtonTimer.reset();
 }
@@ -52,64 +52,65 @@
     return;
 }
 
+void showData(int c){
+    sprintf (lcdData,"tz%d",c);  
+    LCDMess(lcdData);  
+}
+
 void count_backwards(int cnt, int min){
+    gled = !gled;
+    pc.printf("\tT-%d\n\r", cnt);
+    showData(cnt);
+    wait(DATAINTERVAL);
     if(!buttons[1]){
+        pc.printf("    <--reset-->\n\r");
+        pc.printf("Choose new number.\n\r");
         stateToggle = 0;
         cnt = 0;
-        showTitle();
     }
-    gled = !gled;
-    pc.printf("\tT-%d\n\r", cnt);
-    sprintf (lcdData,"tz%d",cnt);  
-    LCDMess(lcdData);  
-    wait(DATAINTERVAL);
     // tail recursion to correct the direction of counting
     if(cnt > min){ 
         count_backwards(cnt-1,min);
     }
 }
 
-void showData(int cnt){
-    sprintf (lcdData,"%d",cnt);  
-    LCDMess(lcdData);  
-}
-
 int main()
 {
+    showTitle();
     initialize_global_vars();
-    showTitle();
-    pc.printf(PROGNAME);
     while (true) {
-        rled = !rled;
         tsidata = tsi.readPercentage();
         count_num = floor(tsidata*51);
-        if(count_num > 2){
-            pc.printf("\n Count down from: %d\n\r", count_num);
-            showData(count_num);
-        }
+        showData(count_num);
         wait(DATAINTERVAL);
         if (ButtonTimer > BUTTONTIME) {
             if(!buttons[0]){
                 stateToggle = 1;
             }
-        if(!buttons[1]){
-            stateToggle = 0;
-            count_num = 0;
-            showTitle();
-        }
+            if(!buttons[1]){
+                stateToggle = 0;
+                count_num = 0;
+                pc.printf("Select count->\n\r");
+            }
         }
         ButtonTimer.reset();
 
         switch (stateToggle) {
             case STOPPEDSTATE:
+                if(count_num > 2){
+                    pc.printf("Count: %d?\n\r", count_num);
+                }
                 showData(count_num);
                 rled = 1.0;
                 gled = 0.0;
                 break;
             case COUNTINGSTATE:
                 if(stateToggle) {
+                    pc.printf("\n Counting down from: %d\n\r", count_num);
                     count_backwards(count_num, count_min);
+                    pc.printf("Select count->\n\r");
                 }
+                stateToggle = 0;
                 rled = 0.0;
                 gled = !gled;
                 break;