NMHU example for light sensor SSD 341
Fork of lightsense_kl46z_states by
Revision 7:8d7089b514ae, committed 2014-09-17
- Comitter:
- scohennm
- Date:
- Wed Sep 17 18:20:10 2014 +0000
- Parent:
- 6:710e18c552f5
- Commit message:
- Demo with no wait() function for NMHU SSD 341
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 710e18c552f5 -r 8d7089b514ae main.cpp --- 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