Stanley Cohen
/
lightsense_kl46z_basic
How to use sensor
Fork of lightsense_kl46z_states_nowait by
Revision 9:f619cdaa7a65, committed 2016-09-09
- Comitter:
- scohennm
- Date:
- Fri Sep 09 19:41:10 2016 +0000
- Parent:
- 8:3b19ecdc4261
- Commit message:
- Changed pc print program name
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 3b19ecdc4261 -r f619cdaa7a65 main.cpp --- a/main.cpp Fri Sep 09 19:31:08 2016 +0000 +++ b/main.cpp Fri Sep 09 19:41:10 2016 +0000 @@ -2,7 +2,7 @@ #include "SLCD.h" -#define PROGNAME "lightsense_kl46z_minmax v1\n\r" +#define PROGNAME "lightsense_kl46z_basic v1\n\r" #define DATATIME 400 // milliseconds #define LCDLEN 10 #define LIGHTSENSORPORT PTE22 @@ -19,32 +19,22 @@ slcd.printf(lMess); } + int main() { - float maxLight = 0; - float minLight = 1.0; - PwmOut greenColor(LED_GREEN); - PwmOut redColor(LED_RED); AnalogIn LightSensor(LIGHTSENSORPORT); float lightData; char lcdData[LCDLEN]; int timeToChangeDF = DATATIME; - // set up timer for next step of Duty Factor timing LEDTimer.start(); LEDTimer.reset(); pc.printf(PROGNAME); - while(true) { if (LEDTimer.read_ms() > timeToChangeDF){ // check for timer time out transtion - lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity - greenColor.write(1.0- lightData); - redColor.write(1.0-lightData); - sprintf(lcdData,"%4.3f",lightData); + lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity + sprintf(lcdData,"%4.3f",lightData); LCDMess(lcdData); - if(lightData > maxLight) maxLight = lightData; - if(lightData < minLight) minLight = lightData; - pc.printf("%4.3f min = %4.3f max = %4.3f\r\n",lightData, minLight, maxLight); timeToChangeDF = DATATIME; LEDTimer.reset(); }