SBart-SSD341-HW9.2

Dependencies:   SLCD mbed

Fork of kl46z_stop_watch_v2 by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
sbart
Date:
Wed Oct 19 05:03:14 2016 +0000
Parent:
1:0d13b6d7907f
Commit message:
SBart-HW-9.2

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Oct 12 15:55:44 2016 +0000
+++ b/main.cpp	Wed Oct 19 05:03:14 2016 +0000
@@ -9,7 +9,7 @@
 #define RBUT PTC3
 #define STOPPEDSTATE 0
 #define TIMINGSTATE  1
-#define RESETTINGSTATE 0
+#define RESETTINGSTATE 2
 #define PRINTDELTA 0.01
 #define LCDCHARLEN 10
 #define BUTTONTIME 0.2
@@ -47,6 +47,7 @@
     wait(TITLEWAIT);
     return;
 }
+
 int main(void) {
     int i;
     char lcdData[LCDCHARLEN];
@@ -63,44 +64,41 @@
     showTitle();
 
      while (true) {
+        bool rbut_pressed = false;
+        bool lbut_pressed = false;
+        
         if (ButtonTimer > BUTTONTIME){
-            for (i=0; i<NUMBUTS; i++){ // index will be 0 or 1 
-                if(!buttons[i]) { // a buttton is pressed
-                    displayState = i; 
-                    switch (displayState){  // this keeps things generic
-                        case TIMINGSTATE: {              
-                         statetoggle = !statetoggle;
-                         break;
-                        }
-                        case RESETTINGSTATE :{
-                        break;
-                        }
-                    }   
-                } // if ! buttons
-            }// for loop to look at buttons
+                if(LBUT) {
+                    displayState = TIMINGSTATE;
+                    lbut_pressed = true;
+                    }
+                else if(RBUT) {
+                    displayState = STOPPEDSTATE;
+                    rbut_pressed = true;
+                    }
+                
+                if(lbut_pressed == true && rbut_pressed == true) {
+                    displayState = RESETTINGSTATE;
+                    }
+                
             ButtonTimer.reset();
             switch (displayState){
-                    /* this goes away
+                    //this goes away
                     case STOPPEDSTATE : {                     
                         rled = 0.0;
                         gled = 1.0;
                         break;
                     }
-                    */
                     case RESETTINGSTATE:
-                        if (!statetoggle){
-                            secondsCount = 0;
-                            displayState = TIMINGSTATE;
-                        }
+                        secondsCount = 0;
+                        displayState = STOPPEDSTATE;
                         rled = 0.0;
                         gled = 1.0;
                         break;
                         
                         
                     case TIMINGSTATE : {
-                        if(statetoggle){
-                            secondsCount = secondsCount + BUTTONTIME; 
-                        }                   
+                        secondsCount = secondsCount + BUTTONTIME;            
                         rled = 1.0;
                         gled = 0.0;
                         break;