mBed + timer + keyboard + keypad

Dependencies:   TextLCD keypad mbed

Revision:
1:9b8e060faeab
Parent:
0:73f8ad8f29bb
Child:
2:0d5060721258
--- a/main.cpp	Sun Sep 28 03:30:04 2014 +0000
+++ b/main.cpp	Sun Sep 28 03:54:16 2014 +0000
@@ -1,7 +1,7 @@
 /*
 CIS 541 - Embedded Systems for Life Critical Applications
 Assignment3
-Timer using mBed 1768 + keypad
+Timer using mBed 1768 + 4x4 keypad
 
 Developers - Jatin Sharma and Samarth Shah
 
@@ -57,11 +57,60 @@
 {
     Index = _index;
     
-    if (Index > -1) {
-            lcd.locate(0,1);
-            lcd.printf("Key:%c", Keytable[Index]);
-            Index = -1;
+    if (Index > -1) 
+    {
+        //lcd.locate(0,1);
+        //lcd.printf("Key:%c", Keytable[Index]);
+        
+        
+        if(Keytable[Index] == '*') 
+        {
+                if(timerState == Reset)
+                {
+                    timerReference.start();
+                    timerDisplay.start();
+                    timerState = Running;
+                }
+                else if(timerState == Paused)
+                {
+                    timerReference.start();
+                    timerDisplay.start();
+                    timerState = Running;
+                }
         }
+        if(Keytable[Index] == '0') 
+        {
+            if(timerState == Running)
+            {
+                timerReference.stop();
+                timerDisplay.stop();
+                timerState = Paused;
+            }
+            
+        } 
+        if(Keytable[Index] == '#') 
+        
+        {  
+            if(timerState == Paused)
+            {
+                // Reset timer
+                timerReference.reset();
+                timerDisplay.reset();
+                timerState = Reset;
+                
+                // Reset variables
+                miliSeconds = seconds = minutes = 0;
+                currentReferenceTime = previousReferenceTime = 0;
+                calculatedTimeInterval = referenceTimeInterval = runningError = 0;
+                lcd.locate(0,0);
+                lcd.printf("00:00:00");
+                lcd.locate(0,1);
+                lcd.printf("000000");
+            }
+        }
+         
+        Index = -1;
+    }
     
     return 0;
 }
@@ -79,6 +128,12 @@
                 timerDisplay.start();
                 timerState = Running;
             }
+            else if(timerState == Paused)
+            {
+                timerReference.start();
+                timerDisplay.start();
+                timerState = Running;
+            }
         }
         if((keyboardInput == 'p' || keyboardInput == 'P')) 
         {
@@ -88,12 +143,7 @@
                 timerDisplay.stop();
                 timerState = Paused;
             }
-            else if(timerState == Paused)
-            {
-                timerReference.start();
-                timerDisplay.start();
-                timerState = Running;
-            }
+            
         } 
         if((keyboardInput == 'r' || keyboardInput == 'R')) 
         {