AMart_ssd447_hw3.2

Dependencies:   SLCD mbed

Fork of lightsense_kl46z_PWM_simple by Stanley Cohen

Revision:
7:8d7089b514ae
Parent:
6:710e18c552f5
Child:
8:ea818c9220fc
--- a/main.cpp	Sun Sep 14 23:45:39 2014 +0000
+++ b/main.cpp	Wed Sep 17 18:20:10 2014 +0000
@@ -5,12 +5,13 @@
 // An State Machine solution to HW 4.1 Q3
 // using wait() for high and low limits.
 //#define PRINTDEBUG
-#define PROGNAME "blink_kl46z_states v2\n\r"
+#define PROGNAME "blink_kl46z_states nowait v1\n\r"
 #define LEDON false
 #define LEDOFF true
 #define LEDTMESS "TRUE"
 #define LEDFMESS "FALS"
 #define BLINKDWELL 400 // milliseconds
+#define LIMITSTAYON 1000
 #define DFDELTA 0.01
 #define PWMTIME 1 // ms (kHz
 #define LCDLEN 10
@@ -58,12 +59,16 @@
                     lightData = (1.0 - LightSensor.read());
                     sprintf(lcdData,"%4.3f",lightData);
                     LCDMess(lcdData);  
+                    timeToChangeDF = BLINKDWELL;
                     if (lightData < LOWLIMIT){ // find appropriate state
                         PGMState = LOWLITE;
+                        timeToChangeDF = LIMITSTAYON;
                     } else if (lightData > HILIMIT){
                         PGMState = HILITE;
+                        timeToChangeDF = LIMITSTAYON;
                     } else {
                         PGMState = NEWBLINK;
+                        timeToChangeDF = BLINKDWELL;
                     }                      
                     
                 }
@@ -83,18 +88,20 @@
                 redColor.write(LEDON);
                 greenColor.write(LEDOFF);
                 // create string for display on LCD
-                wait(ONTIME);       
-                LEDTimer.reset();  // reset the timer
-                PGMState = IDLESTATE;  // go idle state
+                if (LEDTimer.read_ms() > timeToChangeDF){     
+                    LEDTimer.reset();  // reset the timer
+                    PGMState = IDLESTATE;  // go idle state
+                }
                 break;
               }
              case LOWLITE: {              
                 redColor.write(LEDOFF);
                 greenColor.write(LEDON);
                 // create string for display on LCD
-                wait(ONTIME);       
-                LEDTimer.reset();  // reset the timer
-                PGMState = IDLESTATE;  // go idle state
+                if (LEDTimer.read_ms() > timeToChangeDF){     
+                    LEDTimer.reset();  // reset the timer
+                    PGMState = IDLESTATE;  // go idle state
+                }
                 break;
               }
         } // end state machine