Stanley Cohen
/
lightsense_kl46z_PWM__lux
kl46z, lux calc
Fork of lightsense_kl46z_PWM_simple by
Revision 9:96ddab3435d2, committed 2017-02-06
- Comitter:
- scohennm
- Date:
- Mon Feb 06 18:59:14 2017 +0000
- Parent:
- 8:ea818c9220fc
- Commit message:
- measure luc
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r ea818c9220fc -r 96ddab3435d2 main.cpp --- a/main.cpp Mon Jan 25 16:10:38 2016 +0000 +++ b/main.cpp Mon Feb 06 18:59:14 2017 +0000 @@ -6,6 +6,9 @@ #define DATATIME 400 // milliseconds #define LCDLEN 10 #define LIGHTSENSORPORT PTE22 +#define LUXSCALING 1650 // full scale lux 500 lux/volt +#define LIMTMESSAGE "OVER" +#define FULLSCALE 1000.0 @@ -24,6 +27,7 @@ PwmOut redColor(LED_RED); AnalogIn LightSensor(LIGHTSENSORPORT); float lightData; + float luxData; char lcdData[LCDLEN]; int timeToChangeDF = DATATIME; @@ -35,12 +39,18 @@ while(true) { if (LEDTimer.read_ms() > timeToChangeDF){ // check for timer time out transtion + // start out assuming over 1000 lux + sprintf(lcdData,"%s",LIMTMESSAGE); lightData = (1.0 - LightSensor.read()); // show as increasiing with increasing intensity + luxData = lightData * LUXSCALING; + greenColor.write(1.0- lightData); redColor.write(1.0-lightData); - sprintf(lcdData,"%4.3f",lightData); + if( luxData < FULLSCALE){ + sprintf(lcdData,"%4.0f",luxData); + } LCDMess(lcdData); - pc.printf("%4.3f\r\n",lightData); + pc.printf("%4.3f" "%4.0f\r\n",lightData,luxData); timeToChangeDF = DATATIME; LEDTimer.reset(); }