KBrat-SSD541-HW-9.2

Dependencies:   SLCD mbed

Fork of kl46z_stop_watch_v2 by Stanley Cohen

Revision:
2:1d77439751bf
Parent:
1:0d13b6d7907f
--- a/main.cpp	Wed Oct 12 15:55:44 2016 +0000
+++ b/main.cpp	Wed Oct 19 06:42:00 2016 +0000
@@ -9,12 +9,12 @@
 #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
 #define FULLMINUTE 60 //seconds
-#define PROGNAME "kl46z_stop_watch_v1\n\r"
+#define PROGNAME "KBrat-SSD541-HW-9.2"
 #define LCDTITLE "STPW"
 #define TITLEWAIT 2.0
 
@@ -27,8 +27,6 @@
 DigitalIn buttons[NUMBUTS] = {RBUT, LBUT};
 int displayState = STOPPEDSTATE;
 
-
-
 void initialize_global_vars(){
     pc.printf(PROGNAME);
     // set up DAQ timer
@@ -57,17 +55,19 @@
     int minutesCount; // for displaying mininuts
     int seconds; //
     int fifthSeconds;
-    bool statetoggle = false; //was in stopped state.
+    //bool statetoggle = false; //was in stopped state.
     
     initialize_global_vars();
     showTitle();
 
      while (true) {
         if (ButtonTimer > BUTTONTIME){
-            for (i=0; i<NUMBUTS; i++){ // index will be 0 or 1 
-                if(!buttons[i]) { // a buttton is pressed
+            for (i=0; i<NUMBUTS; i++){ // index will be 0 or 1
+                if(!buttons[i]) { // a button is pressed
                     displayState = i; 
-                    switch (displayState){  // this keeps things generic
+                    
+                    
+                   /* switch (displayState){  // this keeps things generic
                         case TIMINGSTATE: {              
                          statetoggle = !statetoggle;
                          break;
@@ -75,20 +75,60 @@
                         case RESETTINGSTATE :{
                         break;
                         }
-                    }   
-                } // if ! buttons
+                    }*/   
+                }else if(!buttons[0] && !buttons[1]){ 
+                        switch (displayState){
+                            case RESETTINGSTATE:{
+                                /*secondsCount = 0;
+                                displayState = TIMINGSTATE;
+                        
+                                rled = 0.0;
+                                gled = 1.0;*/
+                        
+                                break;
+                                }
+                        }
+                    } // if ! buttons
             }// for loop to look at buttons
             ButtonTimer.reset();
+            
             switch (displayState){
-                    /* this goes away
-                    case STOPPEDSTATE : {                     
+                   
+                    case STOPPEDSTATE : { //state 0                  
                         rled = 0.0;
                         gled = 1.0;
                         break;
                     }
-                    */
-                    case RESETTINGSTATE:
-                        if (!statetoggle){
+                        
+                    case TIMINGSTATE : { //state 1    
+                        secondsCount = secondsCount + BUTTONTIME;               
+                        rled = 1.0;
+                        gled = 0.0;
+                        
+                        break;
+                    }
+                        
+                    case RESETTINGSTATE: {//state 2
+                        secondsCount = 0;
+                        displayState = TIMINGSTATE;
+                        
+                        rled = 0.0;
+                        gled = 0.0;
+                        break;
+                        
+                    }
+                    
+                    /*case TIMINGSTATE : { //state 1
+                        if(statetoggle){
+                            secondsCount = secondsCount + BUTTONTIME; 
+                        }        
+                        rled = 1.0;
+                        gled = 0.0;
+                        
+                        break;
+                        
+                    case RESETTINGSTATE: //state 2
+                        if (!statetoggle){ 
                             secondsCount = 0;
                             displayState = TIMINGSTATE;
                         }
@@ -96,15 +136,7 @@
                         gled = 1.0;
                         break;
                         
-                        
-                    case TIMINGSTATE : {
-                        if(statetoggle){
-                            secondsCount = secondsCount + BUTTONTIME; 
-                        }                   
-                        rled = 1.0;
-                        gled = 0.0;
-                        break;
-                    }
+                    }*/
             }
             
             // Parse the seconds